VLCPlaylistTableViewCell.m 23 KB

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