VLCPlaylistTableViewCell.m 23 KB

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