VLCPlaylistCollectionViewCell.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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 "VLC-Swift.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:@"%@ - %@",
  192. [_media formatDuration],
  193. [_media formatSize]];
  194. }
  195. - (void)_updatedDisplayedInformationForKeyPath:(NSString *)keyPath
  196. {
  197. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
  198. if ([self.mediaObject isKindOfClass:[MLFile class]]) {
  199. [self _configureForMLFile:(MLFile *)self.mediaObject];
  200. } else if ([self.mediaObject isKindOfClass:[MLLabel class]]) {
  201. [self _configureForFolder:(MLLabel *)self.mediaObject];
  202. } else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) {
  203. [self _configureForAlbum:(MLAlbum *)self.mediaObject];
  204. } else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]]) {
  205. [self _configureForAlbumTrack:(MLAlbumTrack *)self.mediaObject];
  206. } else if ([self.mediaObject isKindOfClass:[MLShow class]]) {
  207. MLShow *mediaObject = (MLShow *)self.mediaObject;
  208. [self _configureForShow:mediaObject];
  209. if ([keyPath isEqualToString:@"computedThumbnail"] || [keyPath isEqualToString:@"episodes"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
  210. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:mediaObject];
  211. }
  212. } else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
  213. [self _configureForShowEpisode:(MLShowEpisode *)self.mediaObject];
  214. }
  215. if (![self.mediaObject isKindOfClass:[MLShow class]] && ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"]))) {
  216. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject];
  217. }
  218. [self setNeedsDisplay];
  219. }
  220. #pragma mark - presentation
  221. - (void)_configureForShow:(MLShow *)show
  222. {
  223. self.titleLabel.text = show.name;
  224. NSUInteger count = show.episodes.count;
  225. NSString *string = @"";
  226. if (show.releaseYear)
  227. string = [NSString stringWithFormat:@"%@ — ", show.releaseYear];
  228. self.subtitleLabel.text = [string stringByAppendingString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_EPISODES", nil) : NSLocalizedString(@"LIBRARY_SINGLE_EPISODE", nil), count, show.unreadEpisodes.count]];
  229. self.mediaIsUnreadView.hidden = YES;
  230. self.progressView.hidden = YES;
  231. self.folderIconView.image = [UIImage imageNamed:@"tvShow"];
  232. self.folderIconView.hidden = NO;
  233. }
  234. - (void)_configureForAlbumTrack:(MLAlbumTrack *)albumTrack
  235. {
  236. MLFile *anyFileFromTrack = albumTrack.anyFileFromTrack;
  237. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@ — %@", albumTrack.artist, [NSString stringWithFormat:NSLocalizedString(@"LIBRARY_TRACK_N", nil), albumTrack.trackNumber.intValue], [VLCTime timeWithNumber:[anyFileFromTrack duration]]];
  238. self.titleLabel.text = albumTrack.title;
  239. [self _showPositionOfItem:anyFileFromTrack];
  240. self.folderIconView.hidden = YES;
  241. }
  242. - (void)_configureForShowEpisode:(MLShowEpisode *)showEpisode
  243. {
  244. self.titleLabel.text = showEpisode.name;
  245. MLFile *anyFileFromEpisode = showEpisode.files.anyObject;
  246. if (self.titleLabel.text.length < 1) {
  247. self.titleLabel.text = [NSString stringWithFormat:@"S%02dE%02d", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue];
  248. self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
  249. } else
  250. self.subtitleLabel.text = [NSString stringWithFormat:@"S%02dE%02d — %@", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue, [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
  251. [self _showPositionOfItem:anyFileFromEpisode];
  252. self.folderIconView.hidden = YES;
  253. }
  254. - (void)_configureForAlbum:(MLAlbum *)album
  255. {
  256. self.titleLabel.text = album.name;
  257. MLAlbumTrack *anyTrack = [album.tracks anyObject];
  258. NSUInteger count = album.tracks.count;
  259. NSMutableString *string = [[NSMutableString alloc] init];
  260. if (anyTrack) {
  261. if (anyTrack.artist.length > 0) {
  262. [string appendString:anyTrack.artist];
  263. [string appendString:@" — "];
  264. }
  265. }
  266. [string appendString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_TRACKS", nil) : NSLocalizedString(@"LIBRARY_SINGLE_TRACK", nil), count]];
  267. if (album.releaseYear.length > 0)
  268. [string appendFormat:@" — %@", album.releaseYear];
  269. self.subtitleLabel.text = string;
  270. self.mediaIsUnreadView.hidden = YES;
  271. self.progressView.hidden = YES;
  272. self.folderIconView.hidden = YES;
  273. }
  274. - (void)_configureForFolder:(MLLabel *)label
  275. {
  276. self.titleLabel.text = label.name;
  277. NSUInteger count = label.files.count;
  278. self.subtitleLabel.text = (count == 1) ? NSLocalizedString(@"ONE_FILE", nil) : [NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", nil), count];
  279. self.mediaIsUnreadView.hidden = YES;
  280. self.progressView.hidden = YES;
  281. self.folderIconView.image = [UIImage imageNamed:@"folderIcon"];
  282. self.folderIconView.hidden = NO;
  283. }
  284. - (void)_configureForMLFile:(MLFile *)mediaFile
  285. {
  286. if (mediaFile.isAlbumTrack) {
  287. NSString *string = @"";
  288. if (mediaFile.albumTrack.artist)
  289. string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
  290. else if (mediaFile.albumTrack.album.name)
  291. string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
  292. self.titleLabel.text = [string stringByAppendingString:(mediaFile.albumTrack.title.length > 1) ? mediaFile.albumTrack.title : mediaFile.title];
  293. } else
  294. self.titleLabel.text = mediaFile.title;
  295. if (_editing)
  296. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@", [VLCTime timeWithNumber:[mediaFile duration]], [NSByteCountFormatter stringFromByteCount:[mediaFile fileSizeInBytes] countStyle:NSByteCountFormatterCountStyleFile]];
  297. else {
  298. self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[mediaFile duration]]];
  299. if (mediaFile.videoTrack) {
  300. NSString *width = [[mediaFile videoTrack] valueForKey:@"width"];
  301. NSString *height = [[mediaFile videoTrack] valueForKey:@"height"];
  302. if (width.intValue > 0 && height.intValue > 0)
  303. self.subtitleLabel.text = [self.subtitleLabel.text stringByAppendingFormat:@" — %@x%@", width, height];
  304. }
  305. }
  306. [self _showPositionOfItem:mediaFile];
  307. self.folderIconView.hidden = YES;
  308. }
  309. - (void)_showPositionOfItem:(MLFile *)mediaLibraryFile
  310. {
  311. if (!mediaLibraryFile)
  312. return;
  313. CGFloat position = mediaLibraryFile.lastPosition.floatValue;
  314. CGFloat duration = mediaLibraryFile.duration.floatValue;
  315. if (position > .05f && position < .95f && (duration * position - duration) < -60000) {
  316. [(UITextView*)self.mediaIsUnreadView setText:[NSString stringWithFormat:NSLocalizedString(@"LIBRARY_MINUTES_LEFT", nil), [[VLCTime timeWithInt:(duration * position - duration)] minuteStringValue]]];
  317. self.mediaIsUnreadView.hidden = NO;
  318. } else if (position != 0.) {
  319. self.mediaIsUnreadView.hidden = YES;
  320. } else {
  321. [(UILabel *)self.mediaIsUnreadView setText:[NSLocalizedString(@"NEW", nil) capitalizedStringWithLocale:[NSLocale currentLocale]]];
  322. self.mediaIsUnreadView.hidden = NO;
  323. }
  324. }
  325. - (void)showMetadata:(BOOL)showMeta
  326. {
  327. if (showMeta) {
  328. NSMutableString *mediaInfo = [[NSMutableString alloc] init];
  329. MLFile *theFile;
  330. if ([self.mediaObject isKindOfClass:[MLFile class]])
  331. theFile = (MLFile *)self.mediaObject;
  332. else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]])
  333. theFile = [[(MLShowEpisode *)self.mediaObject files]anyObject];
  334. else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]])
  335. theFile = [(MLAlbumTrack *)self.mediaObject anyFileFromTrack];
  336. if (!theFile) {
  337. self.metaDataLabel.hidden = YES;
  338. return;
  339. }
  340. NSMutableArray *videoTracks = [[NSMutableArray alloc] init];
  341. NSMutableArray *audioTracks = [[NSMutableArray alloc] init];
  342. NSMutableArray *spuTracks = [[NSMutableArray alloc] init];
  343. NSArray *tracks = [[theFile tracks] allObjects];
  344. NSUInteger trackCount = tracks.count;
  345. for (NSUInteger x = 0; x < trackCount; x++) {
  346. NSManagedObject *track = tracks[x];
  347. NSString *trackEntityName = [[track entity] name];
  348. if ([trackEntityName isEqualToString:@"VideoTrackInformation"])
  349. [videoTracks addObject:track];
  350. else if ([trackEntityName isEqualToString:@"AudioTrackInformation"])
  351. [audioTracks addObject:track];
  352. else if ([trackEntityName isEqualToString:@"SubtitlesTrackInformation"])
  353. [spuTracks addObject:track];
  354. }
  355. /* print video info */
  356. trackCount = videoTracks.count;
  357. if (trackCount > 0) {
  358. if (trackCount != 1)
  359. [mediaInfo appendFormat:@"%lu video tracks", (unsigned long)trackCount];
  360. else
  361. [mediaInfo appendString:@"1 video track"];
  362. [mediaInfo appendString:@" ("];
  363. for (NSUInteger x = 0; x < trackCount; x++) {
  364. int fourcc = [[videoTracks[x] valueForKey:@"codec"] intValue];
  365. if (x != 0)
  366. [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
  367. else
  368. [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];
  369. }
  370. [mediaInfo appendString:@")"];
  371. }
  372. /* print audio info */
  373. trackCount = audioTracks.count;
  374. if (trackCount > 0) {
  375. if (mediaInfo.length > 0)
  376. [mediaInfo appendString:@"\n\n"];
  377. if (trackCount != 1)
  378. [mediaInfo appendFormat:@"%lu audio tracks", (unsigned long)trackCount];
  379. else
  380. [mediaInfo appendString:@"1 audio track"];
  381. [mediaInfo appendString:@":\n"];
  382. for (NSUInteger x = 0; x < trackCount; x++) {
  383. NSManagedObject *track = audioTracks[x];
  384. int fourcc = [[track valueForKey:@"codec"] intValue];
  385. if (x != 0)
  386. [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
  387. else
  388. [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];
  389. int channelNumber = [[track valueForKey:@"channelsNumber"] intValue];
  390. NSString *language = [track valueForKey:@"language"];
  391. int bitrate = [[track valueForKey:@"bitrate"] intValue];
  392. if (channelNumber != 0 || language != nil || bitrate > 0) {
  393. [mediaInfo appendString:@" ["];
  394. if (bitrate > 0)
  395. [mediaInfo appendFormat:@"%i kbit/s", bitrate / 1024];
  396. if (channelNumber > 0) {
  397. if (bitrate > 0)
  398. [mediaInfo appendString:@", "];
  399. if (channelNumber == 1)
  400. [mediaInfo appendString:@"MONO"];
  401. else if (channelNumber == 2)
  402. [mediaInfo appendString:@"STEREO"];
  403. else
  404. [mediaInfo appendString:@"MULTI-CHANNEL"];
  405. }
  406. if (language != nil) {
  407. if (channelNumber > 0 || bitrate > 0)
  408. [mediaInfo appendString:@", "];
  409. [mediaInfo appendString:[language uppercaseString]];
  410. }
  411. [mediaInfo appendString:@"]"];
  412. }
  413. }
  414. }
  415. [mediaInfo appendString:@"\n\n"];
  416. /* SPU */
  417. trackCount = spuTracks.count;
  418. if (trackCount == 0) {
  419. NSFileManager *fileManager = [NSFileManager defaultManager];
  420. NSString *folderLocation = [theFile.url.path stringByDeletingLastPathComponent];
  421. NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
  422. NSString *fileName = [theFile.path.lastPathComponent stringByDeletingPathExtension];
  423. NSUInteger count = allfiles.count;
  424. NSString *additionalFilePath;
  425. for (unsigned int x = 0; x < count; x++) {
  426. additionalFilePath = [NSString stringWithFormat:@"%@", allfiles[x]];
  427. if ([additionalFilePath isSupportedSubtitleFormat])
  428. if ([additionalFilePath rangeOfString:fileName].location != NSNotFound)
  429. trackCount ++;
  430. }
  431. }
  432. if ((trackCount > 0) || (spuTracks.count > 0)) {
  433. if (mediaInfo.length > 0)
  434. [mediaInfo appendString:@"\n\n"];
  435. if (trackCount != 1)
  436. [mediaInfo appendFormat:@"%lu subtitles tracks", (unsigned long)trackCount];
  437. else
  438. [mediaInfo appendString:@"1 subtitles track"];
  439. if (spuTracks.count > 0) {
  440. [mediaInfo appendString:@" ("];
  441. for (NSUInteger x = 0; x < trackCount; x++) {
  442. NSString *language = [spuTracks[x] valueForKey:@"language"];
  443. if (language) {
  444. if (x != 0)
  445. [mediaInfo appendFormat:@", %@", [language uppercaseString]];
  446. else
  447. [mediaInfo appendString:[language uppercaseString]];
  448. }
  449. }
  450. [mediaInfo appendString:@")"];
  451. }
  452. }
  453. self.metaDataLabel.text = mediaInfo;
  454. videoTracks = audioTracks = spuTracks = nil;
  455. }
  456. void (^animationBlock)(void) = ^() {
  457. self.metaDataLabel.hidden = !showMeta;
  458. };
  459. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  460. self.metaDataLabel.hidden = !showMeta;
  461. };
  462. NSTimeInterval animationDuration = .2;
  463. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  464. }
  465. - (BOOL)showsMetaData
  466. {
  467. return !self.metaDataLabel.hidden;
  468. }
  469. - (void)thumbnailWasUpdated:(NSNotification *)aNotification
  470. {
  471. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
  472. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject refreshCache:YES];
  473. }
  474. - (void)prepareForReuse
  475. {
  476. [super prepareForReuse];
  477. self.media = nil;
  478. self.mediaObject = nil;
  479. self.thumbnailView.image = nil;
  480. self.titleLabel.text = @"";
  481. self.subtitleLabel.text = @"";
  482. self.mediaIsUnreadView.hidden = YES;
  483. self.progressView.hidden = YES;
  484. self.metaDataLabel.hidden = YES;
  485. self.folderIconView.hidden = YES;
  486. self.isSelectedView.hidden = YES;
  487. self.metaDataLabel.hidden = YES;
  488. self.mediaIsUnreadView.hidden = YES;
  489. }
  490. @end