VLCPlaylistTableViewCell.m 22 KB

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