Robert
Robert

Reputation: 38213

How to get the playback % progress from a MPMoviePlayerController

I want to know how far the video had progressed when the user closes the video.

So for I have this:

- (void) moviePlayerDidFinsh:(NSNotification*) notification
{
    MPMoviePlayerController* moviePlayer = notification.object;
    NSLog(@"FINISHED duration was:%f", moviePlayer.duration);
}

initialPlaybackTime and endPlaybackTime both seam to be useless.

Upvotes: 0

Views: 1120

Answers (2)

beryllium
beryllium

Reputation: 29767

There is a property currentPlaybackTime in MPMediaPlayback protocol.

The current position of the playhead. (required)

@property(nonatomic) NSTimeInterval currentPlaybackTime

% value = currentPlaybackTime/duration;

Upvotes: 3

Felix
Felix

Reputation: 35384

The property is currentPlaybackTime (in seconds).

This is only useful if the MPMovieFinishReason is equal to MPMovieFinishReasonUserExited.

NSDictionary* userInfo = [aNotification userInfo];    
MPMovieFinishReason finishReason = [[userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (finishReason == MPMovieFinishReasonUserExited) {
        NSTimeInterval playbackTime = [moviePlayer currentPlaybackTime];
        // ...
}

Upvotes: 1

Related Questions