VLCPlaylistCollectionViewCell.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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 "VLCLibraryViewController.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. _checkboxEmptyImage = [UIImage imageNamed:@"checkboxEmpty"];
  33. _checkboxImage = [UIImage imageNamed:@"checkbox"];
  34. self.metaDataLabel.hidden = YES;
  35. [super awakeFromNib];
  36. }
  37. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  38. {
  39. self.isSelectedView.hidden = !editing;
  40. if (!([_mediaObject isKindOfClass:[MLFile class]] && [_mediaObject.labels count] > 0))
  41. [self shake:editing];
  42. [self selectionUpdate];
  43. [self _updatedDisplayedInformationForKeyPath:@"editing"];
  44. }
  45. - (void)selectionUpdate
  46. {
  47. if (self.selected)
  48. self.isSelectedView.image = _checkboxImage;
  49. else
  50. self.isSelectedView.image = _checkboxEmptyImage;
  51. }
  52. - (void)shake:(BOOL)shake
  53. {
  54. if (shake) {
  55. [UIView animateWithDuration:0.3 animations:^{
  56. self.contentView.transform = CGAffineTransformMakeScale(0.9f, 0.9f);
  57. }];
  58. CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
  59. CGFloat shakeAngle = 0.02f;
  60. animation.values = @[@(-shakeAngle), @(shakeAngle)];
  61. animation.autoreverses = YES;
  62. animation.duration = 0.125;
  63. animation.repeatCount = HUGE_VALF;
  64. [[self layer] addAnimation:animation forKey:@"shakeAnimation"];
  65. self.contentView.layer.cornerRadius = 10.0;
  66. self.contentView.clipsToBounds = YES;
  67. } else {
  68. [UIView animateWithDuration:0.3 animations:^{
  69. self.contentView.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
  70. self.contentView.layer.cornerRadius = 0.0;
  71. self.contentView.clipsToBounds = NO;
  72. }];
  73. [[self layer] removeAnimationForKey:@"shakeAnimation"];
  74. }
  75. }
  76. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  77. {
  78. [self _updatedDisplayedInformationForKeyPath:keyPath];
  79. }
  80. - (void)_removeObserver
  81. {
  82. @try {
  83. if ([_mediaObject isKindOfClass:[MLLabel class]]) {
  84. [_mediaObject removeObserver:self forKeyPath:@"files"];
  85. [_mediaObject removeObserver:self forKeyPath:@"name"];
  86. } else if ([_mediaObject isKindOfClass:[MLShow class]])
  87. [_mediaObject removeObserver:self forKeyPath:@"episodes"];
  88. else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
  89. [_mediaObject removeObserver:self forKeyPath:@"name"];
  90. [_mediaObject removeObserver:self forKeyPath:@"files"];
  91. [_mediaObject removeObserver:self forKeyPath:@"artworkURL"];
  92. [_mediaObject removeObserver:self forKeyPath:@"unread"];
  93. } else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
  94. [_mediaObject removeObserver:self forKeyPath:@"name"];
  95. [_mediaObject removeObserver:self forKeyPath:@"tracks"];
  96. } else if ([_mediaObject isKindOfClass:[MLAlbumTrack class]]) {
  97. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  98. [_mediaObject removeObserver:self forKeyPath:@"artist"];
  99. [_mediaObject removeObserver:self forKeyPath:@"title"];
  100. [_mediaObject removeObserver:self forKeyPath:@"files"];
  101. MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject anyFileFromTrack];
  102. if (anyFileFromTrack)
  103. [anyFileFromTrack removeObserver:self forKeyPath:@"artworkURL"];
  104. } else if ([_mediaObject isKindOfClass:[MLFile class]]) {
  105. [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
  106. [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
  107. [_mediaObject removeObserver:self forKeyPath:@"duration"];
  108. [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
  109. [_mediaObject removeObserver:self forKeyPath:@"title"];
  110. [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
  111. [_mediaObject removeObserver:self forKeyPath:@"unread"];
  112. [_mediaObject removeObserver:self forKeyPath:@"albumTrackNumber"];
  113. [_mediaObject removeObserver:self forKeyPath:@"album"];
  114. [_mediaObject removeObserver:self forKeyPath:@"artist"];
  115. [_mediaObject removeObserver:self forKeyPath:@"genre"];
  116. [[NSNotificationCenter defaultCenter] removeObserver:self];
  117. [(MLFile*)_mediaObject didHide];
  118. }
  119. }
  120. @catch (NSException *exception) {
  121. APLog(@"removing observer failed");
  122. }
  123. }
  124. - (void)_addObserver
  125. {
  126. if ([_mediaObject isKindOfClass:[MLLabel class]]) {
  127. [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
  128. [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
  129. } else if ([_mediaObject isKindOfClass:[MLShow class]])
  130. [_mediaObject addObserver:self forKeyPath:@"episodes" options:0 context:nil];
  131. else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
  132. [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
  133. [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
  134. [_mediaObject addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
  135. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  136. } else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
  137. [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
  138. [_mediaObject addObserver:self forKeyPath:@"tracks" options:0 context:nil];
  139. } else if ([_mediaObject isKindOfClass:[MLAlbumTrack class]]) {
  140. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  141. [_mediaObject addObserver:self forKeyPath:@"artist" options:0 context:nil];
  142. [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
  143. [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
  144. MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject anyFileFromTrack];
  145. if (anyFileFromTrack)
  146. [anyFileFromTrack addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
  147. } else if ([_mediaObject isKindOfClass:[MLFile class]]) {
  148. [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
  149. [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
  150. [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
  151. [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
  152. [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
  153. [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
  154. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  155. [_mediaObject addObserver:self forKeyPath:@"albumTrackNumber" options:0 context:nil];
  156. [_mediaObject addObserver:self forKeyPath:@"album" options:0 context:nil];
  157. [_mediaObject addObserver:self forKeyPath:@"artist" options:0 context:nil];
  158. [_mediaObject addObserver:self forKeyPath:@"genre" options:0 context:nil];
  159. [[NSNotificationCenter defaultCenter] addObserver:self
  160. selector:@selector(thumbnailWasUpdated:)
  161. name:MLFileThumbnailWasUpdated
  162. object:nil];
  163. [(MLFile*)_mediaObject willDisplay];
  164. }
  165. }
  166. - (void)setMediaObject:(MLFile *)mediaObject
  167. {
  168. if (_mediaObject != mediaObject) {
  169. [self _removeObserver];
  170. _mediaObject = mediaObject;
  171. // prevent the cell from recycling the current snap for random contents
  172. self.thumbnailView.image = nil;
  173. [self _addObserver];
  174. }
  175. [self _updatedDisplayedInformationForKeyPath:nil];
  176. }
  177. - (void)_updatedDisplayedInformationForKeyPath:(NSString *)keyPath
  178. {
  179. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
  180. if ([self.mediaObject isKindOfClass:[MLFile class]]) {
  181. [self _configureForMLFile:self.mediaObject];
  182. } else if ([self.mediaObject isKindOfClass:[MLLabel class]]) {
  183. [self _configureForFolder:(MLLabel *)self.mediaObject];
  184. } else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) {
  185. [self _configureForAlbum:(MLAlbum *)self.mediaObject];
  186. } else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]]) {
  187. [self _configureForAlbumTrack:(MLAlbumTrack *)self.mediaObject];
  188. } else if ([self.mediaObject isKindOfClass:[MLShow class]]) {
  189. MLShow *mediaObject = (MLShow *)self.mediaObject;
  190. [self _configureForShow:mediaObject];
  191. if ([keyPath isEqualToString:@"computedThumbnail"] || [keyPath isEqualToString:@"episodes"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
  192. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:mediaObject];
  193. }
  194. } else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
  195. [self _configureForShowEpisode:(MLShowEpisode *)self.mediaObject];
  196. }
  197. if (![self.mediaObject isKindOfClass:[MLShow class]] && ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"]))) {
  198. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject];
  199. }
  200. [self setNeedsDisplay];
  201. }
  202. #pragma mark - presentation
  203. - (void)_configureForShow:(MLShow *)show
  204. {
  205. self.titleLabel.text = show.name;
  206. NSUInteger count = show.episodes.count;
  207. NSString *string = @"";
  208. if (show.releaseYear)
  209. string = [NSString stringWithFormat:@"%@ — ", show.releaseYear];
  210. self.subtitleLabel.text = [string stringByAppendingString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_EPISODES", nil) : NSLocalizedString(@"LIBRARY_SINGLE_EPISODE", nil), count, show.unreadEpisodes.count]];
  211. self.mediaIsUnreadView.hidden = YES;
  212. self.progressView.hidden = YES;
  213. self.folderIconView.image = [UIImage imageNamed:@"tvShow"];
  214. self.folderIconView.hidden = NO;
  215. }
  216. - (void)_configureForAlbumTrack:(MLAlbumTrack *)albumTrack
  217. {
  218. MLFile *anyFileFromTrack = albumTrack.anyFileFromTrack;
  219. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@ — %@", albumTrack.artist, [NSString stringWithFormat:NSLocalizedString(@"LIBRARY_TRACK_N", nil), albumTrack.trackNumber.intValue], [VLCTime timeWithNumber:[anyFileFromTrack duration]]];
  220. self.titleLabel.text = albumTrack.title;
  221. [self _showPositionOfItem:anyFileFromTrack];
  222. self.folderIconView.hidden = YES;
  223. }
  224. - (void)_configureForShowEpisode:(MLShowEpisode *)showEpisode
  225. {
  226. self.titleLabel.text = showEpisode.name;
  227. MLFile *anyFileFromEpisode = showEpisode.files.anyObject;
  228. if (self.titleLabel.text.length < 1) {
  229. self.titleLabel.text = [NSString stringWithFormat:@"S%02dE%02d", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue];
  230. self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
  231. } else
  232. self.subtitleLabel.text = [NSString stringWithFormat:@"S%02dE%02d — %@", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue, [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
  233. [self _showPositionOfItem:anyFileFromEpisode];
  234. self.folderIconView.hidden = YES;
  235. }
  236. - (void)_configureForAlbum:(MLAlbum *)album
  237. {
  238. self.titleLabel.text = album.name;
  239. MLAlbumTrack *anyTrack = [album.tracks anyObject];
  240. NSUInteger count = album.tracks.count;
  241. NSMutableString *string = [[NSMutableString alloc] init];
  242. if (anyTrack) {
  243. if (anyTrack.artist.length > 0) {
  244. [string appendString:anyTrack.artist];
  245. [string appendString:@" — "];
  246. }
  247. }
  248. [string appendString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_TRACKS", nil) : NSLocalizedString(@"LIBRARY_SINGLE_TRACK", nil), count]];
  249. if (album.releaseYear.length > 0)
  250. [string appendFormat:@" — %@", album.releaseYear];
  251. self.subtitleLabel.text = string;
  252. self.mediaIsUnreadView.hidden = YES;
  253. self.progressView.hidden = YES;
  254. self.folderIconView.hidden = YES;
  255. }
  256. - (void)_configureForFolder:(MLLabel *)label
  257. {
  258. self.titleLabel.text = label.name;
  259. NSUInteger count = label.files.count;
  260. self.subtitleLabel.text = (count == 1) ? NSLocalizedString(@"ONE_FILE", nil) : [NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", nil), count];
  261. self.mediaIsUnreadView.hidden = YES;
  262. self.progressView.hidden = YES;
  263. self.folderIconView.image = [UIImage imageNamed:@"folderIcon"];
  264. self.folderIconView.hidden = NO;
  265. }
  266. - (void)_configureForMLFile:(MLFile *)mediaFile
  267. {
  268. if (mediaFile.isAlbumTrack) {
  269. NSString *string = @"";
  270. if (mediaFile.albumTrack.artist)
  271. string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
  272. else if (mediaFile.albumTrack.album.name)
  273. string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
  274. self.titleLabel.text = [string stringByAppendingString:(mediaFile.albumTrack.title.length > 1) ? mediaFile.albumTrack.title : mediaFile.title];
  275. } else
  276. self.titleLabel.text = mediaFile.title;
  277. VLCLibraryViewController *delegate = (VLCLibraryViewController*)self.collectionView.delegate;
  278. if (delegate.isEditing)
  279. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@", [VLCTime timeWithNumber:[mediaFile duration]], [NSByteCountFormatter stringFromByteCount:[mediaFile fileSizeInBytes] countStyle:NSByteCountFormatterCountStyleFile]];
  280. else {
  281. self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[mediaFile duration]]];
  282. if (mediaFile.videoTrack) {
  283. NSString *width = [[mediaFile videoTrack] valueForKey:@"width"];
  284. NSString *height = [[mediaFile videoTrack] valueForKey:@"height"];
  285. if (width.intValue > 0 && height.intValue > 0)
  286. self.subtitleLabel.text = [self.subtitleLabel.text stringByAppendingFormat:@" — %@x%@", width, height];
  287. }
  288. }
  289. [self _showPositionOfItem:mediaFile];
  290. self.folderIconView.hidden = YES;
  291. }
  292. - (void)_showPositionOfItem:(MLFile *)mediaLibraryFile
  293. {
  294. if (!mediaLibraryFile)
  295. return;
  296. CGFloat position = mediaLibraryFile.lastPosition.floatValue;
  297. CGFloat duration = mediaLibraryFile.duration.floatValue;
  298. if (position > .05f && position < .95f && (duration * position - duration) < -60000) {
  299. [(UITextView*)self.mediaIsUnreadView setText:[NSString stringWithFormat:NSLocalizedString(@"LIBRARY_MINUTES_LEFT", nil), [[VLCTime timeWithInt:(duration * position - duration)] minuteStringValue]]];
  300. self.mediaIsUnreadView.hidden = NO;
  301. } else if (position != 0.) {
  302. self.mediaIsUnreadView.hidden = YES;
  303. } else {
  304. [(UILabel *)self.mediaIsUnreadView setText:[NSLocalizedString(@"NEW", nil) capitalizedStringWithLocale:[NSLocale currentLocale]]];
  305. self.mediaIsUnreadView.hidden = NO;
  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 anyFileFromTrack];
  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 = [theFile.url.path stringByDeletingLastPathComponent];
  404. NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
  405. NSString *fileName = [theFile.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. if (spuTracks.count > 0) {
  423. [mediaInfo appendString:@" ("];
  424. for (NSUInteger x = 0; x < trackCount; x++) {
  425. NSString *language = [spuTracks[x] valueForKey:@"language"];
  426. if (language) {
  427. if (x != 0)
  428. [mediaInfo appendFormat:@", %@", [language uppercaseString]];
  429. else
  430. [mediaInfo appendString:[language uppercaseString]];
  431. }
  432. }
  433. [mediaInfo appendString:@")"];
  434. }
  435. }
  436. self.metaDataLabel.text = mediaInfo;
  437. videoTracks = audioTracks = spuTracks = nil;
  438. }
  439. void (^animationBlock)() = ^() {
  440. self.metaDataLabel.hidden = !showMeta;
  441. };
  442. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  443. self.metaDataLabel.hidden = !showMeta;
  444. };
  445. NSTimeInterval animationDuration = .2;
  446. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  447. }
  448. - (BOOL)showsMetaData
  449. {
  450. return !self.metaDataLabel.hidden;
  451. }
  452. - (void)thumbnailWasUpdated:(NSNotification *)aNotification
  453. {
  454. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
  455. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject refreshCache:YES];
  456. }
  457. @end