VLCPlaylistCollectionViewCell.m 24 KB

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