WrightsCS
WrightsCS

Reputation: 50727

MPMoviePlayerViewController Video duration

I have no problem playing the video, just cant seem to get my label to update with the video's duration. (entire video length).

The following method works fine using AVAudioPlayer:

- (void) updateDurationLabel {

    NSURL *url = /* not an issue */
    MPMoviePlayerViewController *video = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

    int duration = video.moviePlayer.playableDuration; /* not the same as AVAudioPlayer */
    int minutesDur = duration / 60;
    int secondsDur = duration % 60;
    NSString *minutesString2 = (minutesDur < 10) ?
              [NSString stringWithFormat:@"0%d", minutesDur] :
              [NSString stringWithFormat:@"%d", minutesDur];
    NSString *secondsString2 = (secondsDur < 10) ?
              [NSString stringWithFormat:@"0%d", secondsDur] :
              [NSString stringWithFormat:@"%d", secondsDur];

    lblDuration.text = [NSString stringWithFormat:@"%@:%@", minutesString2,
                                                            secondsString2];
}

Upvotes: 0

Views: 1829

Answers (1)

Jilouc
Jilouc

Reputation: 12714

I think the duration property may not be accurate until MPMovieDurationAvailableNotification is sent...

Also you're using playableDuration which represents the duration of what have currently been buffered, not the total duration.

Upvotes: 2

Related Questions