VLCPlaylistCollectionViewCell.m 22 KB

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