VLCPlaylistCollectionViewCell.m 22.5 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * VLCPlaylistCollectionViewCell.m
 * VLC for iOS
 *****************************************************************************
5
 * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
6 7 8 9 10
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne # videolan.org>
 *          Tamas Timar <ttimar.vlc # gmail.com>
 *          Gleb Pinigin <gpinigin # gmail.com>
11
 *          Carola Nitz <nitz.carola # googlemail.com>
12 13 14
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/
15 16 17

#import "VLCPlaylistCollectionViewCell.h"
#import "VLCPlaylistViewController.h"
18
#import "VLCThumbnailsCache.h"
19
#import "NSString+SupportedMedia.h"
20

21 22 23 24 25 26 27 28
@interface VLCPlaylistCollectionViewCell ()
{
    UIImage *_checkboxEmptyImage;
    UIImage *_checkboxImage;
}

@end

29 30
@implementation VLCPlaylistCollectionViewCell

31 32 33 34 35
- (void)dealloc
{
    [self _removeObserver];
}

36 37 38 39 40 41 42 43 44
- (void)awakeFromNib
{
    if (SYSTEM_RUNS_IOS7_OR_LATER) {
        _checkboxEmptyImage = [UIImage imageNamed:@"checkboxEmpty"];
        _checkboxImage = [UIImage imageNamed:@"checkbox"];
    } else {
        _checkboxEmptyImage = [UIImage imageNamed:@"checkbox-legacy-empty"];
        _checkboxImage = [UIImage imageNamed:@"checkbox-legacy"];
    }
45
    self.metaDataLabel.hidden = YES;
46 47
}

48 49
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
50
    self.isSelectedView.hidden = !editing;
51 52

    if (!([_mediaObject isKindOfClass:[MLFile class]] && [_mediaObject.labels count] > 0))
53
        [self shake:editing];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
54
    [self selectionUpdate];
55 56 57
    [self _updatedDisplayedInformationForKeyPath:@"editing"];
}

58 59 60
- (void)selectionUpdate
{
    if (self.selected)
61
        self.isSelectedView.image = _checkboxImage;
62
    else
63
        self.isSelectedView.image = _checkboxEmptyImage;
64 65
}

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
- (void)shake:(BOOL)shake
{
    if (shake) {
        [UIView animateWithDuration:0.3 animations:^{
            self.contentView.transform = CGAffineTransformMakeScale(0.9f, 0.9f);
        }];
        CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
        CGFloat shakeAngle = 0.02f;
        animation.values = @[@(-shakeAngle), @(shakeAngle)];
        animation.autoreverses = YES;
        animation.duration = 0.125;
        animation.repeatCount = HUGE_VALF;

        [[self layer] addAnimation:animation forKey:@"shakeAnimation"];
        self.contentView.layer.cornerRadius = 10.0;
        self.contentView.clipsToBounds = YES;
    } else {
        [UIView animateWithDuration:0.3 animations:^{
            self.contentView.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
            self.contentView.layer.cornerRadius = 0.0;
            self.contentView.clipsToBounds = NO;
        }];
        [[self layer] removeAnimationForKey:@"shakeAnimation"];
    }
}

92 93 94 95 96
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    [self _updatedDisplayedInformationForKeyPath:keyPath];
}

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
- (void)_removeObserver
{
    if ([_mediaObject isKindOfClass:[MLLabel class]])
        [_mediaObject removeObserver:self forKeyPath:@"name"];
    else if ([_mediaObject isKindOfClass:[MLShow class]])
        [_mediaObject removeObserver:self forKeyPath:@"episodes"];
    else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
        [_mediaObject removeObserver:self forKeyPath:@"name"];
        [_mediaObject removeObserver:self forKeyPath:@"files"];
        [_mediaObject removeObserver:self forKeyPath:@"artworkURL"];
        [_mediaObject removeObserver:self forKeyPath:@"unread"];
    } else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
        [_mediaObject removeObserver:self forKeyPath:@"name"];
        [_mediaObject removeObserver:self forKeyPath:@"tracks"];
    } else if ([_mediaObject isKindOfClass:[MLFile class]]) {
        [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
        [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
        [_mediaObject removeObserver:self forKeyPath:@"duration"];
        [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
        [_mediaObject removeObserver:self forKeyPath:@"title"];
        [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
        [_mediaObject removeObserver:self forKeyPath:@"unread"];
        [_mediaObject removeObserver:self forKeyPath:@"albumTrackNumber"];
        [_mediaObject removeObserver:self forKeyPath:@"album"];
        [_mediaObject removeObserver:self forKeyPath:@"artist"];
        [_mediaObject removeObserver:self forKeyPath:@"genre"];
        [(MLFile*)_mediaObject didHide];
    }
}

- (void)_addObserver
{
    if ([_mediaObject isKindOfClass:[MLLabel class]])
        [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
    else if ([_mediaObject isKindOfClass:[MLShow class]])
        [_mediaObject addObserver:self forKeyPath:@"episodes" options:0 context:nil];
    else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
        [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
    } else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
        [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"tracks" options:0 context:nil];
    } else if ([_mediaObject isKindOfClass:[MLFile class]]) {
        [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"albumTrackNumber" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"album" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"artist" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"genre" options:0 context:nil];
        [(MLFile*)_mediaObject willDisplay];
    }
}

157 158 159
- (void)setMediaObject:(MLFile *)mediaObject
{
    if (_mediaObject != mediaObject) {
160 161

        [self _removeObserver];
162 163

        _mediaObject = mediaObject;
164 165
        // prevent the cell from recycling the current snap for random contents
        self.thumbnailView.image = nil;
166

167
        [self _addObserver];
168 169 170 171 172 173 174
    }

    [self _updatedDisplayedInformationForKeyPath:nil];
}

- (void)_updatedDisplayedInformationForKeyPath:(NSString *)keyPath
{
175
    self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
176 177
    if ([self.mediaObject isKindOfClass:[MLFile class]]) {
        MLFile *mediaObject = self.mediaObject;
178
        [self _configureForMLFile:mediaObject];
179

180
        if (([keyPath isEqualToString:@"computedThumbnail"] || !keyPath) || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"]))
181
            self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:mediaObject];
182 183 184 185
    } else if ([self.mediaObject isKindOfClass:[MLLabel class]]) {
        MLLabel *mediaObject = (MLLabel *)self.mediaObject;
        [self _configureForFolder:mediaObject];

186
        if ([keyPath isEqualToString:@"files"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
187
            if (mediaObject.files.count != 0)
188
                self.thumbnailView.image = [VLCThumbnailsCache thumbnailForLabel:mediaObject];
189
        }
190 191
    } else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) {
        MLAlbum *mediaObject = (MLAlbum *)self.mediaObject;
192
        [self _configureForAlbum:mediaObject];
193

194 195 196 197
        if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
            MLFile *anyFileFromAnyTrack = [mediaObject.tracks.anyObject files].anyObject;
            self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromAnyTrack];
        }
198 199
    } else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]]) {
        MLAlbumTrack *mediaObject = (MLAlbumTrack *)self.mediaObject;
200
        [self _configureForAlbumTrack:mediaObject];
201

202
        if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || !self.thumbnailView.image) {
203 204 205
            MLFile *anyFileFromTrack = mediaObject.files.anyObject;
            self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromTrack];
        }
206 207
    } else if ([self.mediaObject isKindOfClass:[MLShow class]]) {
        MLShow *mediaObject = (MLShow *)self.mediaObject;
208
        [self _configureForShow:mediaObject];
209

210 211
        if ([keyPath isEqualToString:@"computedThumbnail"] || [keyPath isEqualToString:@"episodes"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
            self.thumbnailView.image = [VLCThumbnailsCache thumbnailForShow:mediaObject];
212 213 214
        }
    } else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
        MLShowEpisode *mediaObject = (MLShowEpisode *)self.mediaObject;
215
        [self _configureForShowEpisode:mediaObject];
216

217
        if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || !self.thumbnailView.image) {
218
            MLFile *anyFileFromEpisode = mediaObject.files.anyObject;
219
            self.thumbnailView.image = [VLCThumbnailsCache thumbnailForMediaFile:anyFileFromEpisode];
220 221 222 223 224 225 226 227
        }
    }

    [self setNeedsDisplay];
}

#pragma mark - presentation

228
- (void)_configureForShow:(MLShow *)show
229 230 231
{
    self.titleLabel.text = show.name;
    NSUInteger count = show.episodes.count;
232 233 234
    NSString *string = @"";
    if (show.releaseYear)
        string = [NSString stringWithFormat:@"%@ — ", show.releaseYear];
235
    self.subtitleLabel.text = [string stringByAppendingString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_EPISODES", nil) : NSLocalizedString(@"LIBRARY_SINGLE_EPISODE", nil), count, show.unreadEpisodes.count]];
236 237
    self.mediaIsUnreadView.hidden = YES;
    self.progressView.hidden = YES;
238
    self.folderIconView.image = [UIImage imageNamed:@"tvShow"];
239
    self.folderIconView.hidden = NO;
240 241
}

242
- (void)_configureForAlbumTrack:(MLAlbumTrack *)albumTrack
243 244 245
{
    MLFile *anyFileFromTrack = albumTrack.files.anyObject;

246
    self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@ — %@", albumTrack.artist, [NSString stringWithFormat:NSLocalizedString(@"LIBRARY_TRACK_N", nil), albumTrack.trackNumber.intValue], [VLCTime timeWithNumber:[anyFileFromTrack duration]]];
247
    self.titleLabel.text = albumTrack.title;
248

249
    [self _showPositionOfItem:anyFileFromTrack];
250
    self.folderIconView.hidden = YES;
251 252
}

253
- (void)_configureForShowEpisode:(MLShowEpisode *)showEpisode
254 255
{
    self.titleLabel.text = showEpisode.name;
256 257

    MLFile *anyFileFromEpisode = showEpisode.files.anyObject;
258
    if (self.titleLabel.text.length < 1) {
259
        self.titleLabel.text = [NSString stringWithFormat:@"S%02dE%02d", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue];
260 261
        self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
    } else
262
        self.subtitleLabel.text = [NSString stringWithFormat:@"S%02dE%02d — %@", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue, [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
263
    [self _showPositionOfItem:anyFileFromEpisode];
264
    self.folderIconView.hidden = YES;
265 266
}

267 268 269 270 271
- (void)_configureForAlbum:(MLAlbum *)album
{
    self.titleLabel.text = album.name;
    MLAlbumTrack *anyTrack = [album.tracks anyObject];
    NSUInteger count = album.tracks.count;
272 273
    NSMutableString *string = [[NSMutableString alloc] init];
    if (anyTrack) {
274 275 276 277
        if (anyTrack.artist.length > 0) {
            [string appendString:anyTrack.artist];
            [string appendString:@" — "];
        }
278
    }
279
    [string appendString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_TRACKS", nil) : NSLocalizedString(@"LIBRARY_SINGLE_TRACK", nil), count]];
280
    if (album.releaseYear.length > 0)
Felix Paul Kühne's avatar
Felix Paul Kühne committed
281
        [string appendFormat:@" — %@", album.releaseYear];
282
    self.subtitleLabel.text = string;
283 284
    self.mediaIsUnreadView.hidden = YES;
    self.progressView.hidden = YES;
285
    self.folderIconView.hidden = YES;
286 287
}

288 289 290 291
- (void)_configureForFolder:(MLLabel *)label
{
    self.titleLabel.text = label.name;
    NSUInteger count = label.files.count;
292
    self.subtitleLabel.text = [NSString stringWithFormat:(count == 1) ? NSLocalizedString(@"LIBRARY_SINGLE_TRACK", nil) : NSLocalizedString(@"LIBRARY_TRACKS", nil), count];
293 294
    self.mediaIsUnreadView.hidden = YES;
    self.progressView.hidden = YES;
295 296
    self.folderIconView.image = [UIImage imageNamed:@"folderIcon"];
    self.folderIconView.hidden = NO;
297 298
}

299
- (void)_configureForMLFile:(MLFile *)mediaFile
300
{
301
    if (mediaFile.isAlbumTrack) {
302 303 304 305 306 307
        NSString *string = @"";
        if (mediaFile.albumTrack.artist)
            string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
        else if (mediaFile.albumTrack.album.name)
            string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
        self.titleLabel.text = [string stringByAppendingString:(mediaFile.albumTrack.title.length > 1) ? mediaFile.albumTrack.title : mediaFile.title];
308 309 310 311 312 313
    } else
        self.titleLabel.text = mediaFile.title;

    VLCPlaylistViewController *delegate = (VLCPlaylistViewController*)self.collectionView.delegate;

    if (delegate.isEditing)
314
        self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@", [VLCTime timeWithNumber:[mediaFile duration]], [NSByteCountFormatter stringFromByteCount:[mediaFile fileSizeInBytes] countStyle:NSByteCountFormatterCountStyleFile]];
315 316 317 318 319 320 321 322 323
    else {
        self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[mediaFile duration]]];
        if (mediaFile.videoTrack) {
            NSString *width = [[mediaFile videoTrack] valueForKey:@"width"];
            NSString *height = [[mediaFile videoTrack] valueForKey:@"height"];
            if (width.intValue > 0 && height.intValue > 0)
                self.subtitleLabel.text = [self.subtitleLabel.text stringByAppendingFormat:@" — %@x%@", width, height];
        }
    }
324
    [self _showPositionOfItem:mediaFile];
325
    self.folderIconView.hidden = YES;
326 327
}

328
- (void)_showPositionOfItem:(MLFile *)mediaLibraryFile
329
{
330
    CGFloat position = mediaLibraryFile.lastPosition.floatValue;
331 332

    if (SYSTEM_RUNS_IOS7_OR_LATER) {
333
        CGFloat duration = mediaLibraryFile.duration.floatValue;
334
        if (position > .05f && position < .95f && (duration * position - duration) < -60000) {
335
            [(UITextView*)self.mediaIsUnreadView setText:[NSString stringWithFormat:NSLocalizedString(@"LIBRARY_MINUTES_LEFT", nil), [[VLCTime timeWithInt:(duration * position - duration)] minuteStringValue]]];
336
            self.mediaIsUnreadView.hidden = NO;
337
        } else if (mediaLibraryFile.unread.intValue) {
338
            [(UILabel *)self.mediaIsUnreadView setText:[NSLocalizedString(@"NEW", nil) capitalizedStringWithLocale:[NSLocale currentLocale]]];
339 340 341 342 343 344 345
            self.mediaIsUnreadView.hidden = NO;
        } else
            self.mediaIsUnreadView.hidden = YES;
    } else {
        self.progressView.progress = position;
        self.progressView.hidden = ((position < .1f) || (position > .95f)) ? YES : NO;
        [self.progressView setNeedsDisplay];
346
        self.mediaIsUnreadView.hidden = !mediaLibraryFile.unread.intValue;
347
    }
348 349
}

350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
- (void)showMetadata:(BOOL)showMeta
{
    if (showMeta) {
        NSMutableString *mediaInfo = [[NSMutableString alloc] init];

        MLFile *theFile;
        if ([self.mediaObject isKindOfClass:[MLFile class]])
            theFile = self.mediaObject;
        else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]])
            theFile = [[(MLShowEpisode *)self.mediaObject files]anyObject];
        else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]])
            theFile = [[(MLAlbumTrack *)self.mediaObject files]anyObject];

        if (!theFile) {
            self.metaDataLabel.hidden = YES;
            return;
        }

        NSMutableArray *videoTracks = [[NSMutableArray alloc] init];
        NSMutableArray *audioTracks = [[NSMutableArray alloc] init];
        NSMutableArray *spuTracks = [[NSMutableArray alloc] init];
        NSArray *tracks = [[theFile tracks] allObjects];
        NSUInteger trackCount = tracks.count;

        for (NSUInteger x = 0; x < trackCount; x++) {
            NSManagedObject *track = tracks[x];
            NSString *trackEntityName = [[track entity] name];
            if ([trackEntityName isEqualToString:@"VideoTrackInformation"])
                [videoTracks addObject:track];
            else if ([trackEntityName isEqualToString:@"AudioTrackInformation"])
                [audioTracks addObject:track];
            else if ([trackEntityName isEqualToString:@"SubtitlesTrackInformation"])
                [spuTracks addObject:track];
        }

        /* print video info */
        trackCount = videoTracks.count;

        if (trackCount > 0) {
389 390 391 392 393
            if (trackCount != 1)
                [mediaInfo appendFormat:@"%lu video tracks", (unsigned long)trackCount];
            else
                [mediaInfo appendString:@"1 video track"];

394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
            [mediaInfo appendString:@" ("];
            for (NSUInteger x = 0; x < trackCount; x++) {
                int fourcc = [[videoTracks[x] valueForKey:@"codec"] intValue];
                if (x != 0)
                    [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
                else
                    [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];
            }
            [mediaInfo appendString:@")"];
        }

        /* print audio info */
        trackCount = audioTracks.count;

        if (trackCount > 0) {
409 410 411 412 413 414 415 416
            if (mediaInfo.length > 0)
                [mediaInfo appendString:@"\n\n"];

            if (trackCount != 1)
                [mediaInfo appendFormat:@"%lu audio tracks", (unsigned long)trackCount];
            else
                [mediaInfo appendString:@"1 audio track"];

417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
            [mediaInfo appendString:@":\n"];
            for (NSUInteger x = 0; x < trackCount; x++) {
                NSManagedObject *track = audioTracks[x];
                int fourcc = [[track valueForKey:@"codec"] intValue];
                if (x != 0)
                    [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
                else
                    [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];

                int channelNumber = [[track valueForKey:@"channelsNumber"] intValue];
                NSString *language = [track valueForKey:@"language"];
                int bitrate = [[track valueForKey:@"bitrate"] intValue];
                if (channelNumber != 0 || language != nil || bitrate > 0) {
                    [mediaInfo appendString:@" ["];

                    if (bitrate > 0)
                        [mediaInfo appendFormat:@"%i kbit/s", bitrate / 1024];

                    if (channelNumber > 0) {
                        if (bitrate > 0)
                            [mediaInfo appendString:@", "];

                        if (channelNumber == 1)
                            [mediaInfo appendString:@"MONO"];
                        else if (channelNumber == 2)
                            [mediaInfo appendString:@"STEREO"];
                        else
                            [mediaInfo appendString:@"MULTI-CHANNEL"];
                    }

                    if (language != nil) {
                        if (channelNumber > 0 || bitrate > 0)
                            [mediaInfo appendString:@", "];

                        [mediaInfo appendString:[language uppercaseString]];
                    }

                    [mediaInfo appendString:@"]"];
                }
            }
        }
        [mediaInfo appendString:@"\n\n"];

        /* SPU */
        trackCount = spuTracks.count;
462 463 464 465 466 467 468 469 470 471 472 473 474 475
        if (trackCount == 0) {
            NSFileManager *fileManager = [NSFileManager defaultManager];
            NSString *folderLocation = [[[NSURL URLWithString:theFile.url] path] stringByDeletingLastPathComponent];
            NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
            NSString *fileName = [[[[NSURL URLWithString:theFile.url] path] lastPathComponent] stringByDeletingPathExtension];
            NSUInteger count = allfiles.count;
            NSString *additionalFilePath;
            for (unsigned int x = 0; x < count; x++) {
                additionalFilePath = [NSString stringWithFormat:@"%@", allfiles[x]];
                if ([additionalFilePath isSupportedSubtitleFormat])
                    if ([additionalFilePath rangeOfString:fileName].location != NSNotFound)
                        trackCount ++;
            }
        }
476

477
        if ((trackCount > 0) && (spuTracks.count > 0)) {
478 479 480 481 482 483 484 485 486
            if (mediaInfo.length > 0)
                [mediaInfo appendString:@"\n\n"];

            if (trackCount != 1)
                [mediaInfo appendFormat:@"%lu subtitles tracks", (unsigned long)trackCount];
            else
                [mediaInfo appendString:@"1 subtitles track"];


487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
            [mediaInfo appendString:@" ("];
            for (NSUInteger x = 0; x < trackCount; x++) {
                NSString *language = [spuTracks[x] valueForKey:@"language"];

                if (language) {
                    if (x != 0)
                        [mediaInfo appendFormat:@", %@", [language uppercaseString]];
                    else
                        [mediaInfo appendString:[language uppercaseString]];
                }
            }
            [mediaInfo appendString:@")"];
        }

        self.metaDataLabel.text = mediaInfo;
        videoTracks = audioTracks = spuTracks = nil;
    }

    void (^animationBlock)() = ^() {
        self.metaDataLabel.hidden = !showMeta;
    };

    void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
        self.metaDataLabel.hidden = !showMeta;
    };

    NSTimeInterval animationDuration = .2;
    [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
}

- (BOOL)showsMetaData
{
    return !self.metaDataLabel.hidden;
}

522
@end