Christopher Nassar
Christopher Nassar

Reputation: 554

MPMoviePlayerController next previous buttons incorrect notifications

I have MPMoviePlayerController and I just want to detect next/previous buttons in order to play a playlist accordingly, I added notifications, but it always returns MPMoviePlaybackStateStopped state instead of MPMoviePlaybackStateSeekingForward or MPMoviePlaybackStateSeekingBackward.

Here is the code:

[[NSNotificationCenter defaultCenter] addObserver:self // the object listening / "observing" to the notification
                                         selector:@selector(stateChanged:) // method to call when the notification was pushed
                                             name:MPMoviePlayerPlaybackStateDidChangeNotification // notification the observer should listen to
                                           object:nil];

And in the call back function:

-(void)stateChanged:(NSNotification *)notification{
MPMoviePlaybackState state = self.moviePlayerViewController.moviePlayer.playbackState;
switch (state) {
    case MPMoviePlaybackStateStopped:
        NSLog(@"Stopped");
        break;
    case MPMoviePlaybackStateInterrupted:
        NSLog(@"Interrupted");
        break;
    case MPMoviePlaybackStateSeekingForward:
        NSLog(@"forward");
        currentIndex++;
        ForcePlay = true;
        [self PlayVideo:currentIndex];
        break;
    case MPMoviePlaybackStateSeekingBackward:
        NSLog(@"backward");
        currentIndex--;
        ForcePlay = true;
        [self PlayVideo:currentIndex];
        break;
    case MPMoviePlaybackStatePaused:
        NSLog(@"paused");
        break;
    case MPMoviePlaybackStatePlaying:
        NSLog(@"playing");
        break;
}
}

Upvotes: 1

Views: 633

Answers (1)

Pangu
Pangu

Reputation: 3819

The default controls of MPMoviePlayerController has only basic functionality. Tapping Prev/Next will only call one state, i.e. MPMoviePlaybackStateStopped.

If you want the ability to detect prev/next, you have to implement your own custom controls and perform actions on each button individually by hiding the default controls with MPMovieControlStyleNone

For example in Obj-C:

[prevBtn addTarget:self action:@selector(onClick:) 
forControlEvents:UIControlEventTouchUpInside];

[nextBtn addTarget:self action:@selector(onClick:) 
forControlEvents:UIControlEventTouchUpInside];

Upvotes: -1

Related Questions