VLCPlaylistCollectionViewCell.m 23 KB

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