VLCPlaylistTableViewCell.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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)awakeFromNib
  25. {
  26. [super awakeFromNib];
  27. UIView *bgColorView = [[UIView alloc] init];
  28. bgColorView.backgroundColor = [UIColor clearColor];
  29. [self setSelectedBackgroundView:bgColorView];
  30. }
  31. - (void)dealloc
  32. {
  33. [self _removeObserver];
  34. }
  35. - (void)prepareForReuse
  36. {
  37. [super prepareForReuse];
  38. [self collapsWithAnimation:NO];
  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 anyFileFromTrack];
  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 anyFileFromTrack];
  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.anyFileFromTrack;
  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 (position != 0.) {
  291. self.mediaIsUnreadView.hidden = YES;
  292. } else {
  293. [(UILabel *)self.mediaIsUnreadView setText:[NSLocalizedString(@"NEW", nil) capitalizedStringWithLocale:[NSLocale currentLocale]]];
  294. self.mediaIsUnreadView.hidden = NO;
  295. }
  296. }
  297. - (void)longTouchGestureAction:(UIGestureRecognizer *)recognizer
  298. {
  299. _isExpanded = YES;
  300. CGRect frame = self.frame;
  301. frame.size.height = 180.;
  302. BOOL metaHidden = NO;
  303. MLFile *theFile;
  304. if ([self.mediaObject isKindOfClass:[MLFile class]])
  305. theFile = (MLFile *)self.mediaObject;
  306. else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]])
  307. theFile = [(MLShowEpisode *)self.mediaObject anyFileFromEpisode];
  308. else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]])
  309. theFile = [(MLAlbumTrack *)self.mediaObject anyFileFromTrack];
  310. NSMutableString *mediaInfo = [[NSMutableString alloc] init];
  311. if (theFile) {
  312. NSMutableArray *videoTracks = [[NSMutableArray alloc] init];
  313. NSMutableArray *audioTracks = [[NSMutableArray alloc] init];
  314. NSMutableArray *spuTracks = [[NSMutableArray alloc] init];
  315. NSArray *tracks = [[theFile tracks] allObjects];
  316. NSUInteger trackCount = tracks.count;
  317. for (NSUInteger x = 0; x < trackCount; x++) {
  318. NSManagedObject *track = tracks[x];
  319. NSString *trackEntityName = [[track entity] name];
  320. if ([trackEntityName isEqualToString:@"VideoTrackInformation"])
  321. [videoTracks addObject:track];
  322. else if ([trackEntityName isEqualToString:@"AudioTrackInformation"])
  323. [audioTracks addObject:track];
  324. else if ([trackEntityName isEqualToString:@"SubtitlesTrackInformation"])
  325. [spuTracks addObject:track];
  326. }
  327. /* print video info */
  328. trackCount = videoTracks.count;
  329. if (trackCount > 0) {
  330. if (trackCount != 1)
  331. [mediaInfo appendFormat:@"%lu video tracks", (unsigned long)trackCount];
  332. else
  333. [mediaInfo appendString:@"1 video track"];
  334. [mediaInfo appendString:@" ("];
  335. for (NSUInteger x = 0; x < trackCount; x++) {
  336. int fourcc = [[videoTracks[x] valueForKey:@"codec"] intValue];
  337. if (x != 0)
  338. [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
  339. else
  340. [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];
  341. }
  342. [mediaInfo appendString:@")"];
  343. }
  344. /* print audio info */
  345. trackCount = audioTracks.count;
  346. if (trackCount > 0) {
  347. if (mediaInfo.length > 0)
  348. [mediaInfo appendString:@"\n\n"];
  349. if (trackCount != 1)
  350. [mediaInfo appendFormat:@"%lu audio tracks", (unsigned long)trackCount];
  351. else
  352. [mediaInfo appendString:@"1 audio track"];
  353. [mediaInfo appendString:@":\n"];
  354. for (NSUInteger x = 0; x < trackCount; x++) {
  355. NSManagedObject *track = audioTracks[x];
  356. int fourcc = [[track valueForKey:@"codec"] intValue];
  357. if (x != 0)
  358. [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
  359. else
  360. [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];
  361. int channelNumber = [[track valueForKey:@"channelsNumber"] intValue];
  362. NSString *language = [track valueForKey:@"language"];
  363. int bitrate = [[track valueForKey:@"bitrate"] intValue];
  364. if (channelNumber != 0 || language != nil || bitrate > 0) {
  365. [mediaInfo appendString:@" ["];
  366. if (bitrate > 0)
  367. [mediaInfo appendFormat:@"%i kbit/s", bitrate / 1024];
  368. if (channelNumber > 0) {
  369. if (bitrate > 0)
  370. [mediaInfo appendString:@", "];
  371. if (channelNumber == 1)
  372. [mediaInfo appendString:@"MONO"];
  373. else if (channelNumber == 2)
  374. [mediaInfo appendString:@"STEREO"];
  375. else
  376. [mediaInfo appendString:@"MULTI-CHANNEL"];
  377. }
  378. if (language != nil) {
  379. if (channelNumber > 0 || bitrate > 0)
  380. [mediaInfo appendString:@", "];
  381. [mediaInfo appendString:[language uppercaseString]];
  382. }
  383. [mediaInfo appendString:@"]"];
  384. }
  385. }
  386. }
  387. /* SPU */
  388. trackCount = spuTracks.count;
  389. if (trackCount == 0) {
  390. NSFileManager *fileManager = [NSFileManager defaultManager];
  391. NSString *folderLocation = [theFile.url.path stringByDeletingLastPathComponent];
  392. NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
  393. NSString *fileName = [theFile.path.lastPathComponent stringByDeletingPathExtension];
  394. NSUInteger count = allfiles.count;
  395. NSString *additionalFilePath;
  396. for (unsigned int x = 0; x < count; x++) {
  397. additionalFilePath = [NSString stringWithFormat:@"%@", allfiles[x]];
  398. if ([additionalFilePath isSupportedSubtitleFormat])
  399. if ([additionalFilePath rangeOfString:fileName].location != NSNotFound)
  400. trackCount ++;
  401. }
  402. }
  403. if ((trackCount > 0) || (spuTracks.count > 0)) {
  404. if (mediaInfo.length > 0)
  405. [mediaInfo appendString:@"\n\n"];
  406. if (trackCount != 1)
  407. [mediaInfo appendFormat:@"%lu subtitles tracks", (unsigned long)trackCount];
  408. else
  409. [mediaInfo appendString:@"1 subtitles track"];
  410. if (spuTracks.count > 0) {
  411. [mediaInfo appendString:@" ("];
  412. for (NSUInteger x = 0; x < trackCount; x++) {
  413. NSString *language = [spuTracks[x] valueForKey:@"language"];
  414. if (language) {
  415. if (x != 0)
  416. [mediaInfo appendFormat:@", %@", [language uppercaseString]];
  417. else
  418. [mediaInfo appendString:[language uppercaseString]];
  419. }
  420. }
  421. [mediaInfo appendString:@")"];
  422. }
  423. }
  424. self.metaDataLabel.text = mediaInfo;
  425. [self.metaDataLabel sizeToFit];
  426. [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)];
  427. videoTracks = audioTracks = spuTracks = nil;
  428. } else
  429. self.metaDataLabel.text = @"";
  430. void (^animationBlock)() = ^() {
  431. self.frame = frame;
  432. self.metaDataLabel.hidden = metaHidden;
  433. };
  434. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  435. self.frame = frame;
  436. self.metaDataLabel.hidden = metaHidden;
  437. };
  438. NSTimeInterval animationDuration = .2;
  439. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  440. }
  441. - (void)collapsWithAnimation:(BOOL)animate
  442. {
  443. _isExpanded = NO;
  444. if (!animate) {
  445. self.metaDataLabel.hidden = YES;
  446. CGRect frame = self.frame;
  447. frame.size.height = 90.;
  448. self.frame = frame;
  449. return;
  450. }
  451. CGRect frame = self.frame;
  452. frame.size.height = 90.;
  453. BOOL metaHidden = YES;
  454. void (^animationBlock)() = ^() {
  455. self.frame = frame;
  456. self.metaDataLabel.hidden = metaHidden;
  457. };
  458. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  459. self.frame = frame;
  460. self.metaDataLabel.hidden = metaHidden;
  461. };
  462. NSTimeInterval animationDuration = .2;
  463. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  464. }
  465. - (void)thumbnailWasUpdated:(NSNotification *)aNotification
  466. {
  467. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
  468. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject refreshCache:YES];
  469. }
  470. @end