user1285498
user1285498

Reputation: 39

MPMoviePlayerViewController repeat count

I am playing a video using MPMoviePlayerViewController.

I have repeat mode as MPMovieRepeatModeOne so that the video may play in a loop.

Is there any method that I can use to get the repeat count of the played video.

Upvotes: 1

Views: 215

Answers (2)

XLE_22
XLE_22

Reputation: 5671

To my knowledge, you cannot use the MPMoviePlayerPlaybackDidFinishNotification with the repeat mode because it will be triggered only if you get out of the video not if you repeat it.

If you use the repeat mode, you will only have a change of state [=> PLAY (end of the former video)... PAUSED (former video)... PLAY (beginning of the new video)] detected thanks to the MPMoviePlayerPlaybackStateDidChangeNotification but the didFinishNotification won't be in the loop.

At first sight, you should store previous states of the player to follow this pattern for instance:

  1. [stateCurrentTime (PLAY)] > (playingDuration - 1 sec) ==> end of your video

  2. [stateCurrentTime (PAUSED)] < 0.5 sec ==> transitional state between former and new video

  3. [stateCurrentTime (PLAY)] < 1 sec ==> beginning of your new video.

... And if someone succeeds in finding a way using MPMoviePlayerPlaybackDidFinishNotification, I'll be definitely interested in it because the behavior of this notification doesn't go together with repeat mode.

Upvotes: 1

aramusss
aramusss

Reputation: 2401

You can add a Notification:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(introMovieFinished:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:self.moviePlayerController];

And then use this notification to detect when video finished a loop:

- (void)introMovieFinished:(NSNotification *)notification
{
    if (notification.object == self.moviePlayerController) {
        NSInteger reason = [[notification.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
        if (reason == MPMovieFinishReasonPlaybackEnded)
        {
            NSLog(@"Video has looped!");
        }
    }
}

Upvotes: 1

Related Questions