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