VLCPlaylistCollectionViewCell.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. [self _configureForMLFile:self.mediaObject];
  158. } else if ([self.mediaObject isKindOfClass:[MLLabel class]]) {
  159. [self _configureForFolder:(MLLabel *)self.mediaObject];
  160. } else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) {
  161. [self _configureForAlbum:(MLAlbum *)self.mediaObject];
  162. } else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]]) {
  163. [self _configureForAlbumTrack:(MLAlbumTrack *)self.mediaObject];
  164. } else if ([self.mediaObject isKindOfClass:[MLShow class]]) {
  165. MLShow *mediaObject = (MLShow *)self.mediaObject;
  166. [self _configureForShow:mediaObject];
  167. if ([keyPath isEqualToString:@"computedThumbnail"] || [keyPath isEqualToString:@"episodes"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
  168. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:mediaObject];
  169. }
  170. } else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
  171. [self _configureForShowEpisode:(MLShowEpisode *)self.mediaObject];
  172. }
  173. if (![self.mediaObject isKindOfClass:[MLShow class]] && ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"]))) {
  174. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject];
  175. }
  176. [self setNeedsDisplay];
  177. }
  178. #pragma mark - presentation
  179. - (void)_configureForShow:(MLShow *)show
  180. {
  181. self.titleLabel.text = show.name;
  182. NSUInteger count = show.episodes.count;
  183. NSString *string = @"";
  184. if (show.releaseYear)
  185. string = [NSString stringWithFormat:@"%@ — ", show.releaseYear];
  186. self.subtitleLabel.text = [string stringByAppendingString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_EPISODES", nil) : NSLocalizedString(@"LIBRARY_SINGLE_EPISODE", nil), count, show.unreadEpisodes.count]];
  187. self.mediaIsUnreadView.hidden = YES;
  188. self.progressView.hidden = YES;
  189. self.folderIconView.image = [UIImage imageNamed:@"tvShow"];
  190. self.folderIconView.hidden = NO;
  191. }
  192. - (void)_configureForAlbumTrack:(MLAlbumTrack *)albumTrack
  193. {
  194. MLFile *anyFileFromTrack = albumTrack.files.anyObject;
  195. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@ — %@", albumTrack.artist, [NSString stringWithFormat:NSLocalizedString(@"LIBRARY_TRACK_N", nil), albumTrack.trackNumber.intValue], [VLCTime timeWithNumber:[anyFileFromTrack duration]]];
  196. self.titleLabel.text = albumTrack.title;
  197. [self _showPositionOfItem:anyFileFromTrack];
  198. self.folderIconView.hidden = YES;
  199. }
  200. - (void)_configureForShowEpisode:(MLShowEpisode *)showEpisode
  201. {
  202. self.titleLabel.text = showEpisode.name;
  203. MLFile *anyFileFromEpisode = showEpisode.files.anyObject;
  204. if (self.titleLabel.text.length < 1) {
  205. self.titleLabel.text = [NSString stringWithFormat:@"S%02dE%02d", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue];
  206. self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
  207. } else
  208. self.subtitleLabel.text = [NSString stringWithFormat:@"S%02dE%02d — %@", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue, [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
  209. [self _showPositionOfItem:anyFileFromEpisode];
  210. self.folderIconView.hidden = YES;
  211. }
  212. - (void)_configureForAlbum:(MLAlbum *)album
  213. {
  214. self.titleLabel.text = album.name;
  215. MLAlbumTrack *anyTrack = [album.tracks anyObject];
  216. NSUInteger count = album.tracks.count;
  217. NSMutableString *string = [[NSMutableString alloc] init];
  218. if (anyTrack) {
  219. if (anyTrack.artist.length > 0) {
  220. [string appendString:anyTrack.artist];
  221. [string appendString:@" — "];
  222. }
  223. }
  224. [string appendString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_TRACKS", nil) : NSLocalizedString(@"LIBRARY_SINGLE_TRACK", nil), count]];
  225. if (album.releaseYear.length > 0)
  226. [string appendFormat:@" — %@", album.releaseYear];
  227. self.subtitleLabel.text = string;
  228. self.mediaIsUnreadView.hidden = YES;
  229. self.progressView.hidden = YES;
  230. self.folderIconView.hidden = YES;
  231. }
  232. - (void)_configureForFolder:(MLLabel *)label
  233. {
  234. self.titleLabel.text = label.name;
  235. NSUInteger count = label.files.count;
  236. self.subtitleLabel.text = [NSString stringWithFormat:(count == 1) ? NSLocalizedString(@"LIBRARY_SINGLE_TRACK", nil) : NSLocalizedString(@"LIBRARY_TRACKS", nil), count];
  237. self.mediaIsUnreadView.hidden = YES;
  238. self.progressView.hidden = YES;
  239. self.folderIconView.image = [UIImage imageNamed:@"folderIcon"];
  240. self.folderIconView.hidden = NO;
  241. }
  242. - (void)_configureForMLFile:(MLFile *)mediaFile
  243. {
  244. if (mediaFile.isAlbumTrack) {
  245. NSString *string = @"";
  246. if (mediaFile.albumTrack.artist)
  247. string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
  248. else if (mediaFile.albumTrack.album.name)
  249. string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
  250. self.titleLabel.text = [string stringByAppendingString:(mediaFile.albumTrack.title.length > 1) ? mediaFile.albumTrack.title : mediaFile.title];
  251. } else
  252. self.titleLabel.text = mediaFile.title;
  253. VLCPlaylistViewController *delegate = (VLCPlaylistViewController*)self.collectionView.delegate;
  254. if (delegate.isEditing)
  255. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@", [VLCTime timeWithNumber:[mediaFile duration]], [NSByteCountFormatter stringFromByteCount:[mediaFile fileSizeInBytes] countStyle:NSByteCountFormatterCountStyleFile]];
  256. else {
  257. self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[mediaFile duration]]];
  258. if (mediaFile.videoTrack) {
  259. NSString *width = [[mediaFile videoTrack] valueForKey:@"width"];
  260. NSString *height = [[mediaFile videoTrack] valueForKey:@"height"];
  261. if (width.intValue > 0 && height.intValue > 0)
  262. self.subtitleLabel.text = [self.subtitleLabel.text stringByAppendingFormat:@" — %@x%@", width, height];
  263. }
  264. }
  265. [self _showPositionOfItem:mediaFile];
  266. self.folderIconView.hidden = YES;
  267. }
  268. - (void)_showPositionOfItem:(MLFile *)mediaLibraryFile
  269. {
  270. CGFloat position = mediaLibraryFile.lastPosition.floatValue;
  271. if (SYSTEM_RUNS_IOS7_OR_LATER) {
  272. CGFloat duration = mediaLibraryFile.duration.floatValue;
  273. if (position > .05f && position < .95f && (duration * position - duration) < -60000) {
  274. [(UITextView*)self.mediaIsUnreadView setText:[NSString stringWithFormat:NSLocalizedString(@"LIBRARY_MINUTES_LEFT", nil), [[VLCTime timeWithInt:(duration * position - duration)] minuteStringValue]]];
  275. self.mediaIsUnreadView.hidden = NO;
  276. } else if (mediaLibraryFile.unread.intValue) {
  277. [(UILabel *)self.mediaIsUnreadView setText:[NSLocalizedString(@"NEW", nil) capitalizedStringWithLocale:[NSLocale currentLocale]]];
  278. self.mediaIsUnreadView.hidden = NO;
  279. } else
  280. self.mediaIsUnreadView.hidden = YES;
  281. } else {
  282. self.progressView.progress = position;
  283. self.progressView.hidden = ((position < .1f) || (position > .95f)) ? YES : NO;
  284. [self.progressView setNeedsDisplay];
  285. self.mediaIsUnreadView.hidden = !mediaLibraryFile.unread.intValue;
  286. }
  287. }
  288. - (void)showMetadata:(BOOL)showMeta
  289. {
  290. if (showMeta) {
  291. NSMutableString *mediaInfo = [[NSMutableString alloc] init];
  292. MLFile *theFile;
  293. if ([self.mediaObject isKindOfClass:[MLFile class]])
  294. theFile = self.mediaObject;
  295. else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]])
  296. theFile = [[(MLShowEpisode *)self.mediaObject files]anyObject];
  297. else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]])
  298. theFile = [[(MLAlbumTrack *)self.mediaObject files]anyObject];
  299. if (!theFile) {
  300. self.metaDataLabel.hidden = YES;
  301. return;
  302. }
  303. NSMutableArray *videoTracks = [[NSMutableArray alloc] init];
  304. NSMutableArray *audioTracks = [[NSMutableArray alloc] init];
  305. NSMutableArray *spuTracks = [[NSMutableArray alloc] init];
  306. NSArray *tracks = [[theFile tracks] allObjects];
  307. NSUInteger trackCount = tracks.count;
  308. for (NSUInteger x = 0; x < trackCount; x++) {
  309. NSManagedObject *track = tracks[x];
  310. NSString *trackEntityName = [[track entity] name];
  311. if ([trackEntityName isEqualToString:@"VideoTrackInformation"])
  312. [videoTracks addObject:track];
  313. else if ([trackEntityName isEqualToString:@"AudioTrackInformation"])
  314. [audioTracks addObject:track];
  315. else if ([trackEntityName isEqualToString:@"SubtitlesTrackInformation"])
  316. [spuTracks addObject:track];
  317. }
  318. /* print video info */
  319. trackCount = videoTracks.count;
  320. if (trackCount > 0) {
  321. if (trackCount != 1)
  322. [mediaInfo appendFormat:@"%lu video tracks", (unsigned long)trackCount];
  323. else
  324. [mediaInfo appendString:@"1 video track"];
  325. [mediaInfo appendString:@" ("];
  326. for (NSUInteger x = 0; x < trackCount; x++) {
  327. int fourcc = [[videoTracks[x] valueForKey:@"codec"] intValue];
  328. if (x != 0)
  329. [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
  330. else
  331. [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];
  332. }
  333. [mediaInfo appendString:@")"];
  334. }
  335. /* print audio info */
  336. trackCount = audioTracks.count;
  337. if (trackCount > 0) {
  338. if (mediaInfo.length > 0)
  339. [mediaInfo appendString:@"\n\n"];
  340. if (trackCount != 1)
  341. [mediaInfo appendFormat:@"%lu audio tracks", (unsigned long)trackCount];
  342. else
  343. [mediaInfo appendString:@"1 audio track"];
  344. [mediaInfo appendString:@":\n"];
  345. for (NSUInteger x = 0; x < trackCount; x++) {
  346. NSManagedObject *track = audioTracks[x];
  347. int fourcc = [[track valueForKey:@"codec"] intValue];
  348. if (x != 0)
  349. [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
  350. else
  351. [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];
  352. int channelNumber = [[track valueForKey:@"channelsNumber"] intValue];
  353. NSString *language = [track valueForKey:@"language"];
  354. int bitrate = [[track valueForKey:@"bitrate"] intValue];
  355. if (channelNumber != 0 || language != nil || bitrate > 0) {
  356. [mediaInfo appendString:@" ["];
  357. if (bitrate > 0)
  358. [mediaInfo appendFormat:@"%i kbit/s", bitrate / 1024];
  359. if (channelNumber > 0) {
  360. if (bitrate > 0)
  361. [mediaInfo appendString:@", "];
  362. if (channelNumber == 1)
  363. [mediaInfo appendString:@"MONO"];
  364. else if (channelNumber == 2)
  365. [mediaInfo appendString:@"STEREO"];
  366. else
  367. [mediaInfo appendString:@"MULTI-CHANNEL"];
  368. }
  369. if (language != nil) {
  370. if (channelNumber > 0 || bitrate > 0)
  371. [mediaInfo appendString:@", "];
  372. [mediaInfo appendString:[language uppercaseString]];
  373. }
  374. [mediaInfo appendString:@"]"];
  375. }
  376. }
  377. }
  378. [mediaInfo appendString:@"\n\n"];
  379. /* SPU */
  380. trackCount = spuTracks.count;
  381. if (trackCount == 0) {
  382. NSFileManager *fileManager = [NSFileManager defaultManager];
  383. NSString *folderLocation = [theFile.url.path stringByDeletingLastPathComponent];
  384. NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
  385. NSString *fileName = [theFile.path.lastPathComponent stringByDeletingPathExtension];
  386. NSUInteger count = allfiles.count;
  387. NSString *additionalFilePath;
  388. for (unsigned int x = 0; x < count; x++) {
  389. additionalFilePath = [NSString stringWithFormat:@"%@", allfiles[x]];
  390. if ([additionalFilePath isSupportedSubtitleFormat])
  391. if ([additionalFilePath rangeOfString:fileName].location != NSNotFound)
  392. trackCount ++;
  393. }
  394. }
  395. if ((trackCount > 0) && (spuTracks.count > 0)) {
  396. if (mediaInfo.length > 0)
  397. [mediaInfo appendString:@"\n\n"];
  398. if (trackCount != 1)
  399. [mediaInfo appendFormat:@"%lu subtitles tracks", (unsigned long)trackCount];
  400. else
  401. [mediaInfo appendString:@"1 subtitles track"];
  402. [mediaInfo appendString:@" ("];
  403. for (NSUInteger x = 0; x < trackCount; x++) {
  404. NSString *language = [spuTracks[x] valueForKey:@"language"];
  405. if (language) {
  406. if (x != 0)
  407. [mediaInfo appendFormat:@", %@", [language uppercaseString]];
  408. else
  409. [mediaInfo appendString:[language uppercaseString]];
  410. }
  411. }
  412. [mediaInfo appendString:@")"];
  413. }
  414. self.metaDataLabel.text = mediaInfo;
  415. videoTracks = audioTracks = spuTracks = nil;
  416. }
  417. void (^animationBlock)() = ^() {
  418. self.metaDataLabel.hidden = !showMeta;
  419. };
  420. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  421. self.metaDataLabel.hidden = !showMeta;
  422. };
  423. NSTimeInterval animationDuration = .2;
  424. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  425. }
  426. - (BOOL)showsMetaData
  427. {
  428. return !self.metaDataLabel.hidden;
  429. }
  430. @end