VLCPlaylistCollectionViewCell.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. /*****************************************************************************
  2. * VLCPlaylistCollectionViewCell.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Tamas Timar <ttimar.vlc # gmail.com>
  10. * Gleb Pinigin <gpinigin # gmail.com>
  11. * Carola Nitz <nitz.carola # googlemail.com>
  12. *
  13. * Refer to the COPYING file of the official project for license.
  14. *****************************************************************************/
  15. #import "VLCPlaylistCollectionViewCell.h"
  16. #import "VLCPlaylistViewController.h"
  17. #import "VLCThumbnailsCache.h"
  18. #import "NSString+SupportedMedia.h"
  19. @interface VLCPlaylistCollectionViewCell ()
  20. {
  21. UIImage *_checkboxEmptyImage;
  22. UIImage *_checkboxImage;
  23. }
  24. @end
  25. @implementation VLCPlaylistCollectionViewCell
  26. - (void)dealloc
  27. {
  28. [self _removeObserver];
  29. }
  30. - (void)awakeFromNib
  31. {
  32. if (SYSTEM_RUNS_IOS7_OR_LATER) {
  33. _checkboxEmptyImage = [UIImage imageNamed:@"checkboxEmpty"];
  34. _checkboxImage = [UIImage imageNamed:@"checkbox"];
  35. } else {
  36. _checkboxEmptyImage = [UIImage imageNamed:@"checkbox-legacy-empty"];
  37. _checkboxImage = [UIImage imageNamed:@"checkbox-legacy"];
  38. }
  39. self.metaDataLabel.hidden = YES;
  40. }
  41. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  42. {
  43. self.isSelectedView.hidden = !editing;
  44. if (!([_mediaObject isKindOfClass:[MLFile class]] && [_mediaObject.labels count] > 0))
  45. [self shake:editing];
  46. [self selectionUpdate];
  47. [self _updatedDisplayedInformationForKeyPath:@"editing"];
  48. }
  49. - (void)selectionUpdate
  50. {
  51. if (self.selected)
  52. self.isSelectedView.image = _checkboxImage;
  53. else
  54. self.isSelectedView.image = _checkboxEmptyImage;
  55. }
  56. - (void)shake:(BOOL)shake
  57. {
  58. if (shake) {
  59. [UIView animateWithDuration:0.3 animations:^{
  60. self.contentView.transform = CGAffineTransformMakeScale(0.9f, 0.9f);
  61. }];
  62. CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
  63. CGFloat shakeAngle = 0.02f;
  64. animation.values = @[@(-shakeAngle), @(shakeAngle)];
  65. animation.autoreverses = YES;
  66. animation.duration = 0.125;
  67. animation.repeatCount = HUGE_VALF;
  68. [[self layer] addAnimation:animation forKey:@"shakeAnimation"];
  69. self.contentView.layer.cornerRadius = 10.0;
  70. self.contentView.clipsToBounds = YES;
  71. } else {
  72. [UIView animateWithDuration:0.3 animations:^{
  73. self.contentView.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
  74. self.contentView.layer.cornerRadius = 0.0;
  75. self.contentView.clipsToBounds = NO;
  76. }];
  77. [[self layer] removeAnimationForKey:@"shakeAnimation"];
  78. }
  79. }
  80. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  81. {
  82. [self _updatedDisplayedInformationForKeyPath:keyPath];
  83. }
  84. - (void)_removeObserver
  85. {
  86. if ([_mediaObject isKindOfClass:[MLLabel class]])
  87. [_mediaObject removeObserver:self forKeyPath:@"name"];
  88. else if ([_mediaObject isKindOfClass:[MLShow class]])
  89. [_mediaObject removeObserver:self forKeyPath:@"episodes"];
  90. else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
  91. [_mediaObject removeObserver:self forKeyPath:@"name"];
  92. [_mediaObject removeObserver:self forKeyPath:@"files"];
  93. [_mediaObject removeObserver:self forKeyPath:@"artworkURL"];
  94. [_mediaObject removeObserver:self forKeyPath:@"unread"];
  95. } else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
  96. [_mediaObject removeObserver:self forKeyPath:@"name"];
  97. [_mediaObject removeObserver:self forKeyPath:@"tracks"];
  98. } else if ([_mediaObject isKindOfClass:[MLFile class]]) {
  99. [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
  100. [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
  101. [_mediaObject removeObserver:self forKeyPath:@"duration"];
  102. [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
  103. [_mediaObject removeObserver:self forKeyPath:@"title"];
  104. [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
  105. [_mediaObject removeObserver:self forKeyPath:@"unread"];
  106. [_mediaObject removeObserver:self forKeyPath:@"albumTrackNumber"];
  107. [_mediaObject removeObserver:self forKeyPath:@"album"];
  108. [_mediaObject removeObserver:self forKeyPath:@"artist"];
  109. [_mediaObject removeObserver:self forKeyPath:@"genre"];
  110. [(MLFile*)_mediaObject didHide];
  111. }
  112. }
  113. - (void)_addObserver
  114. {
  115. if ([_mediaObject isKindOfClass:[MLLabel class]])
  116. [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
  117. else if ([_mediaObject isKindOfClass:[MLShow class]])
  118. [_mediaObject addObserver:self forKeyPath:@"episodes" options:0 context:nil];
  119. else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
  120. [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
  121. [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
  122. [_mediaObject addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
  123. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  124. } else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
  125. [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
  126. [_mediaObject addObserver:self forKeyPath:@"tracks" options:0 context:nil];
  127. } else if ([_mediaObject isKindOfClass:[MLFile class]]) {
  128. [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
  129. [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
  130. [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
  131. [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
  132. [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
  133. [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
  134. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  135. [_mediaObject addObserver:self forKeyPath:@"albumTrackNumber" options:0 context:nil];
  136. [_mediaObject addObserver:self forKeyPath:@"album" options:0 context:nil];
  137. [_mediaObject addObserver:self forKeyPath:@"artist" options:0 context:nil];
  138. [_mediaObject addObserver:self forKeyPath:@"genre" options:0 context:nil];
  139. [(MLFile*)_mediaObject willDisplay];
  140. }
  141. }
  142. - (void)setMediaObject:(MLFile *)mediaObject
  143. {
  144. if (_mediaObject != mediaObject) {
  145. [self _removeObserver];
  146. _mediaObject = mediaObject;
  147. // prevent the cell from recycling the current snap for random contents
  148. self.thumbnailView.image = nil;
  149. [self _addObserver];
  150. }
  151. [self _updatedDisplayedInformationForKeyPath:nil];
  152. }
  153. - (void)_updatedDisplayedInformationForKeyPath:(NSString *)keyPath
  154. {
  155. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
  156. if ([self.mediaObject isKindOfClass:[MLFile class]]) {
  157. MLFile *mediaObject = self.mediaObject;
  158. [self _configureForMLFile:mediaObject];
  159. if (([keyPath isEqualToString:@"computedThumbnail"] || !keyPath) || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"]))
  160. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:mediaObject];
  161. } else if ([self.mediaObject isKindOfClass:[MLLabel class]]) {
  162. MLLabel *mediaObject = (MLLabel *)self.mediaObject;
  163. [self _configureForFolder:mediaObject];
  164. if ([keyPath isEqualToString:@"files"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
  165. if (mediaObject.files.count != 0)
  166. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForLabel:mediaObject];
  167. }
  168. } else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) {
  169. MLAlbum *mediaObject = (MLAlbum *)self.mediaObject;
  170. [self _configureForAlbum:mediaObject];
  171. if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
  172. MLFile *anyFileFromAnyTrack = [mediaObject.tracks.anyObject files].anyObject;
  173. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromAnyTrack];
  174. }
  175. } else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]]) {
  176. MLAlbumTrack *mediaObject = (MLAlbumTrack *)self.mediaObject;
  177. [self _configureForAlbumTrack:mediaObject];
  178. if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || !self.thumbnailView.image) {
  179. MLFile *anyFileFromTrack = mediaObject.files.anyObject;
  180. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromTrack];
  181. }
  182. } else if ([self.mediaObject isKindOfClass:[MLShow class]]) {
  183. MLShow *mediaObject = (MLShow *)self.mediaObject;
  184. [self _configureForShow:mediaObject];
  185. if ([keyPath isEqualToString:@"computedThumbnail"] || [keyPath isEqualToString:@"episodes"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
  186. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForShow:mediaObject];
  187. }
  188. } else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
  189. MLShowEpisode *mediaObject = (MLShowEpisode *)self.mediaObject;
  190. [self _configureForShowEpisode:mediaObject];
  191. if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || !self.thumbnailView.image) {
  192. MLFile *anyFileFromEpisode = mediaObject.files.anyObject;
  193. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromEpisode];
  194. }
  195. }
  196. [self setNeedsDisplay];
  197. }
  198. #pragma mark - presentation
  199. - (void)_configureForShow:(MLShow *)show
  200. {
  201. self.titleLabel.text = show.name;
  202. NSUInteger count = show.episodes.count;
  203. NSString *string = @"";
  204. if (show.releaseYear)
  205. string = [NSString stringWithFormat:@"%@ — ", show.releaseYear];
  206. self.subtitleLabel.text = [string stringByAppendingString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_EPISODES", nil) : NSLocalizedString(@"LIBRARY_SINGLE_EPISODE", nil), count, show.unreadEpisodes.count]];
  207. self.mediaIsUnreadView.hidden = YES;
  208. self.progressView.hidden = YES;
  209. self.folderIconView.image = [UIImage imageNamed:@"tvShow"];
  210. self.folderIconView.hidden = NO;
  211. }
  212. - (void)_configureForAlbumTrack:(MLAlbumTrack *)albumTrack
  213. {
  214. MLFile *anyFileFromTrack = albumTrack.files.anyObject;
  215. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@ — %@", albumTrack.artist, [NSString stringWithFormat:NSLocalizedString(@"LIBRARY_TRACK_N", nil), albumTrack.trackNumber.intValue], [VLCTime timeWithNumber:[anyFileFromTrack duration]]];
  216. self.titleLabel.text = albumTrack.title;
  217. [self _showPositionOfItem:anyFileFromTrack];
  218. self.folderIconView.hidden = YES;
  219. }
  220. - (void)_configureForShowEpisode:(MLShowEpisode *)showEpisode
  221. {
  222. self.titleLabel.text = showEpisode.name;
  223. MLFile *anyFileFromEpisode = showEpisode.files.anyObject;
  224. if (self.titleLabel.text.length < 1) {
  225. self.titleLabel.text = [NSString stringWithFormat:@"S%02dE%02d", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue];
  226. self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
  227. } else
  228. self.subtitleLabel.text = [NSString stringWithFormat:@"S%02dE%02d — %@", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue, [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
  229. [self _showPositionOfItem:anyFileFromEpisode];
  230. self.folderIconView.hidden = YES;
  231. }
  232. - (void)_configureForAlbum:(MLAlbum *)album
  233. {
  234. self.titleLabel.text = album.name;
  235. MLAlbumTrack *anyTrack = [album.tracks anyObject];
  236. NSUInteger count = album.tracks.count;
  237. NSMutableString *string = [[NSMutableString alloc] init];
  238. if (anyTrack) {
  239. if (anyTrack.artist.length > 0) {
  240. [string appendString:anyTrack.artist];
  241. [string appendString:@" — "];
  242. }
  243. }
  244. [string appendString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_TRACKS", nil) : NSLocalizedString(@"LIBRARY_SINGLE_TRACK", nil), count]];
  245. if (album.releaseYear.length > 0)
  246. [string appendFormat:@" — %@", album.releaseYear];
  247. self.subtitleLabel.text = string;
  248. self.mediaIsUnreadView.hidden = YES;
  249. self.progressView.hidden = YES;
  250. self.folderIconView.hidden = YES;
  251. }
  252. - (void)_configureForFolder:(MLLabel *)label
  253. {
  254. self.titleLabel.text = label.name;
  255. NSUInteger count = label.files.count;
  256. self.subtitleLabel.text = [NSString stringWithFormat:(count == 1) ? NSLocalizedString(@"LIBRARY_SINGLE_TRACK", nil) : NSLocalizedString(@"LIBRARY_TRACKS", nil), count];
  257. self.mediaIsUnreadView.hidden = YES;
  258. self.progressView.hidden = YES;
  259. self.folderIconView.image = [UIImage imageNamed:@"folderIcon"];
  260. self.folderIconView.hidden = NO;
  261. }
  262. - (void)_configureForMLFile:(MLFile *)mediaFile
  263. {
  264. if (mediaFile.isAlbumTrack) {
  265. NSString *string = @"";
  266. if (mediaFile.albumTrack.artist)
  267. string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
  268. else if (mediaFile.albumTrack.album.name)
  269. string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
  270. self.titleLabel.text = [string stringByAppendingString:(mediaFile.albumTrack.title.length > 1) ? mediaFile.albumTrack.title : mediaFile.title];
  271. } else
  272. self.titleLabel.text = mediaFile.title;
  273. VLCPlaylistViewController *delegate = (VLCPlaylistViewController*)self.collectionView.delegate;
  274. if (delegate.isEditing)
  275. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@", [VLCTime timeWithNumber:[mediaFile duration]], [NSByteCountFormatter stringFromByteCount:[mediaFile fileSizeInBytes] countStyle:NSByteCountFormatterCountStyleFile]];
  276. else {
  277. self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[mediaFile duration]]];
  278. if (mediaFile.videoTrack) {
  279. NSString *width = [[mediaFile videoTrack] valueForKey:@"width"];
  280. NSString *height = [[mediaFile videoTrack] valueForKey:@"height"];
  281. if (width.intValue > 0 && height.intValue > 0)
  282. self.subtitleLabel.text = [self.subtitleLabel.text stringByAppendingFormat:@" — %@x%@", width, height];
  283. }
  284. }
  285. [self _showPositionOfItem:mediaFile];
  286. self.folderIconView.hidden = YES;
  287. }
  288. - (void)_showPositionOfItem:(MLFile *)mediaLibraryFile
  289. {
  290. CGFloat position = mediaLibraryFile.lastPosition.floatValue;
  291. if (SYSTEM_RUNS_IOS7_OR_LATER) {
  292. CGFloat duration = mediaLibraryFile.duration.floatValue;
  293. if (position > .05f && position < .95f && (duration * position - duration) < -60000) {
  294. [(UITextView*)self.mediaIsUnreadView setText:[NSString stringWithFormat:NSLocalizedString(@"LIBRARY_MINUTES_LEFT", nil), [[VLCTime timeWithInt:(duration * position - duration)] minuteStringValue]]];
  295. self.mediaIsUnreadView.hidden = NO;
  296. } else if (mediaLibraryFile.unread.intValue) {
  297. [(UILabel *)self.mediaIsUnreadView setText:[NSLocalizedString(@"NEW", nil) capitalizedStringWithLocale:[NSLocale currentLocale]]];
  298. self.mediaIsUnreadView.hidden = NO;
  299. } else
  300. self.mediaIsUnreadView.hidden = YES;
  301. } else {
  302. self.progressView.progress = position;
  303. self.progressView.hidden = ((position < .1f) || (position > .95f)) ? YES : NO;
  304. [self.progressView setNeedsDisplay];
  305. self.mediaIsUnreadView.hidden = !mediaLibraryFile.unread.intValue;
  306. }
  307. }
  308. - (void)showMetadata:(BOOL)showMeta
  309. {
  310. if (showMeta) {
  311. NSMutableString *mediaInfo = [[NSMutableString alloc] init];
  312. MLFile *theFile;
  313. if ([self.mediaObject isKindOfClass:[MLFile class]])
  314. theFile = self.mediaObject;
  315. else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]])
  316. theFile = [[(MLShowEpisode *)self.mediaObject files]anyObject];
  317. else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]])
  318. theFile = [[(MLAlbumTrack *)self.mediaObject files]anyObject];
  319. if (!theFile) {
  320. self.metaDataLabel.hidden = YES;
  321. return;
  322. }
  323. NSMutableArray *videoTracks = [[NSMutableArray alloc] init];
  324. NSMutableArray *audioTracks = [[NSMutableArray alloc] init];
  325. NSMutableArray *spuTracks = [[NSMutableArray alloc] init];
  326. NSArray *tracks = [[theFile tracks] allObjects];
  327. NSUInteger trackCount = tracks.count;
  328. for (NSUInteger x = 0; x < trackCount; x++) {
  329. NSManagedObject *track = tracks[x];
  330. NSString *trackEntityName = [[track entity] name];
  331. if ([trackEntityName isEqualToString:@"VideoTrackInformation"])
  332. [videoTracks addObject:track];
  333. else if ([trackEntityName isEqualToString:@"AudioTrackInformation"])
  334. [audioTracks addObject:track];
  335. else if ([trackEntityName isEqualToString:@"SubtitlesTrackInformation"])
  336. [spuTracks addObject:track];
  337. }
  338. /* print video info */
  339. trackCount = videoTracks.count;
  340. if (trackCount > 0) {
  341. if (trackCount != 1)
  342. [mediaInfo appendFormat:@"%lu video tracks", (unsigned long)trackCount];
  343. else
  344. [mediaInfo appendString:@"1 video track"];
  345. [mediaInfo appendString:@" ("];
  346. for (NSUInteger x = 0; x < trackCount; x++) {
  347. int fourcc = [[videoTracks[x] valueForKey:@"codec"] intValue];
  348. if (x != 0)
  349. [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
  350. else
  351. [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];
  352. }
  353. [mediaInfo appendString:@")"];
  354. }
  355. /* print audio info */
  356. trackCount = audioTracks.count;
  357. if (trackCount > 0) {
  358. if (mediaInfo.length > 0)
  359. [mediaInfo appendString:@"\n\n"];
  360. if (trackCount != 1)
  361. [mediaInfo appendFormat:@"%lu audio tracks", (unsigned long)trackCount];
  362. else
  363. [mediaInfo appendString:@"1 audio track"];
  364. [mediaInfo appendString:@":\n"];
  365. for (NSUInteger x = 0; x < trackCount; x++) {
  366. NSManagedObject *track = audioTracks[x];
  367. int fourcc = [[track valueForKey:@"codec"] intValue];
  368. if (x != 0)
  369. [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
  370. else
  371. [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];
  372. int channelNumber = [[track valueForKey:@"channelsNumber"] intValue];
  373. NSString *language = [track valueForKey:@"language"];
  374. int bitrate = [[track valueForKey:@"bitrate"] intValue];
  375. if (channelNumber != 0 || language != nil || bitrate > 0) {
  376. [mediaInfo appendString:@" ["];
  377. if (bitrate > 0)
  378. [mediaInfo appendFormat:@"%i kbit/s", bitrate / 1024];
  379. if (channelNumber > 0) {
  380. if (bitrate > 0)
  381. [mediaInfo appendString:@", "];
  382. if (channelNumber == 1)
  383. [mediaInfo appendString:@"MONO"];
  384. else if (channelNumber == 2)
  385. [mediaInfo appendString:@"STEREO"];
  386. else
  387. [mediaInfo appendString:@"MULTI-CHANNEL"];
  388. }
  389. if (language != nil) {
  390. if (channelNumber > 0 || bitrate > 0)
  391. [mediaInfo appendString:@", "];
  392. [mediaInfo appendString:[language uppercaseString]];
  393. }
  394. [mediaInfo appendString:@"]"];
  395. }
  396. }
  397. }
  398. [mediaInfo appendString:@"\n\n"];
  399. /* SPU */
  400. trackCount = spuTracks.count;
  401. if (trackCount == 0) {
  402. NSFileManager *fileManager = [NSFileManager defaultManager];
  403. NSString *folderLocation = [[[NSURL URLWithString:theFile.url] path] stringByDeletingLastPathComponent];
  404. NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
  405. NSString *fileName = [[[[NSURL URLWithString:theFile.url] path] lastPathComponent] stringByDeletingPathExtension];
  406. NSUInteger count = allfiles.count;
  407. NSString *additionalFilePath;
  408. for (unsigned int x = 0; x < count; x++) {
  409. additionalFilePath = [NSString stringWithFormat:@"%@", allfiles[x]];
  410. if ([additionalFilePath isSupportedSubtitleFormat])
  411. if ([additionalFilePath rangeOfString:fileName].location != NSNotFound)
  412. trackCount ++;
  413. }
  414. }
  415. if ((trackCount > 0) && (spuTracks.count > 0)) {
  416. if (mediaInfo.length > 0)
  417. [mediaInfo appendString:@"\n\n"];
  418. if (trackCount != 1)
  419. [mediaInfo appendFormat:@"%lu subtitles tracks", (unsigned long)trackCount];
  420. else
  421. [mediaInfo appendString:@"1 subtitles track"];
  422. [mediaInfo appendString:@" ("];
  423. for (NSUInteger x = 0; x < trackCount; x++) {
  424. NSString *language = [spuTracks[x] valueForKey:@"language"];
  425. if (language) {
  426. if (x != 0)
  427. [mediaInfo appendFormat:@", %@", [language uppercaseString]];
  428. else
  429. [mediaInfo appendString:[language uppercaseString]];
  430. }
  431. }
  432. [mediaInfo appendString:@")"];
  433. }
  434. self.metaDataLabel.text = mediaInfo;
  435. videoTracks = audioTracks = spuTracks = nil;
  436. }
  437. void (^animationBlock)() = ^() {
  438. self.metaDataLabel.hidden = !showMeta;
  439. };
  440. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  441. self.metaDataLabel.hidden = !showMeta;
  442. };
  443. NSTimeInterval animationDuration = .2;
  444. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  445. }
  446. - (BOOL)showsMetaData
  447. {
  448. return !self.metaDataLabel.hidden;
  449. }
  450. @end