VLCPlaylistTableViewCell.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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 anyFileFromTrack];
  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 anyFileFromTrack];
  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.anyFileFromTrack;
  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 (position != 0.) {
  290. self.mediaIsUnreadView.hidden = YES;
  291. } else {
  292. [(UILabel *)self.mediaIsUnreadView setText:[NSLocalizedString(@"NEW", nil) capitalizedStringWithLocale:[NSLocale currentLocale]]];
  293. self.mediaIsUnreadView.hidden = NO;
  294. }
  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 anyFileFromEpisode];
  307. else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]])
  308. theFile = [(MLAlbumTrack *)self.mediaObject anyFileFromTrack];
  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. [self.metaDataLabel sizeToFit];
  423. [self.metaDataLabel setFrame:CGRectMake((self.frame.size.width - self.metaDataLabel.frame.size.width)/2, self.metaDataLabel.frame.origin.y, self.metaDataLabel.frame.size.width, self.metaDataLabel.frame.size.height)];
  424. videoTracks = audioTracks = spuTracks = nil;
  425. } else
  426. self.metaDataLabel.text = @"";
  427. void (^animationBlock)() = ^() {
  428. self.frame = frame;
  429. self.metaDataLabel.hidden = metaHidden;
  430. };
  431. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  432. self.frame = frame;
  433. self.metaDataLabel.hidden = metaHidden;
  434. };
  435. NSTimeInterval animationDuration = .2;
  436. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  437. }
  438. - (void)collapsWithAnimation:(BOOL)animate
  439. {
  440. _isExpanded = NO;
  441. if (!animate) {
  442. self.metaDataLabel.hidden = YES;
  443. CGRect frame = self.frame;
  444. frame.size.height = 90.;
  445. self.frame = frame;
  446. return;
  447. }
  448. CGRect frame = self.frame;
  449. frame.size.height = 90.;
  450. BOOL metaHidden = YES;
  451. void (^animationBlock)() = ^() {
  452. self.frame = frame;
  453. self.metaDataLabel.hidden = metaHidden;
  454. };
  455. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  456. self.frame = frame;
  457. self.metaDataLabel.hidden = metaHidden;
  458. };
  459. NSTimeInterval animationDuration = .2;
  460. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  461. }
  462. - (void)thumbnailWasUpdated:(NSNotification *)aNotification
  463. {
  464. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
  465. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject refreshCache:YES];
  466. }
  467. @end