Reputation: 156
I am trying to call a function when a user presses pause in the movieplayer (ie. MPMoviePlaybackStatePaused from the NSNotificationCenter), but only when they press pause. Unfortunately, when the user seeks forward or backward (MPMoviePlaybackStateSeekingForward or MPMoviePlaybackStateSeekingBackward) the movieplayer causes an automatic pause event then proceeds with the seek event after a short delay. Would there be any way to detect that a pause was done without it coming from a seek event.
Thank-you !
Upvotes: 0
Views: 1773
Reputation: 459
Maybe a little late for your problem but I found another why to explain this behavior:
Every time you try to FWD MPMoviePlaybackStateSeekingForward(4) or RWD MPMoviePlaybackStateSeekingBackward(5) there is a MPMoviePlaybackStatePaused(2) before and a MPMoviePlaybackStatePlaying(1) after. So you can easily track the [MPMoviePlayerController currentPlaybackTime] before and after the event and check if its a pause (both values the same), fwd (initial < final) or rwd (initial > final).
MPMoviePlayerController *mp1= (MPMoviePlayerController *)[notification object];
NSLog(@"Movie State is: %d",[mp1 playbackState]);
float curPlaybackTime = round(2.0f * [mp1 currentPlaybackTime]) / 2.0f;
switch ([mp1 playbackState]) {
case 0:
NSLog(@"******* video has stopped");
NSLog(@"TIME: %f",[mp1 currentPlaybackTime]);
break;
case 1:
NSLog(@"******* video is playing after being paused or moved.");
NSLog(@"TIME: %f",curPlaybackTime);
if (curPlaybackTime==st_time) {
if(st_time>0.0){ //if 0 it is a starting video.
NSLog(@"Sending a Pause event");
}
}else if(curPlaybackTime>st_time){
NSLog(@"Sending a Forward event");
}else{
NSLog(@"Sending a Backaward event");
}
break;
case 2:
NSLog(@"******* video is paused");
st_time=round(2.0f * [mp1 currentPlaybackTime]) / 2.0f;
NSLog(@"TIME: %f",st_time);
break;
case 3:
NSLog(@"******* video was interrupted");
break;
case 4:
NSLog(@"******* video is seeking forward");
st_time=round(2.0f * [mp1 currentPlaybackTime]) / 2.0f;
NSLog(@"TIME: %f",st_time);
break;
case 5:
NSLog(@"******* video is seeking Backwards");
st_time=round(2.0f * [mp1 currentPlaybackTime]) / 2.0f;
NSLog(@"TIME: %f",st_time);
break;
default:
break;
}
A little float round is needed because I found times for pausing are some milliseconds different.
Upvotes: 1
Reputation: 156
Solved this by adding a timer:
- (void)moviePlayerPlaybackStateDidChanged:(NSNotification *)notification
{
NSLog(@"VODViewer - moviePlayerPlaybackStateDidChanged()");
if(moviePlayerController.playbackState == MPMoviePlaybackStatePlaying)
{
self.movieIsSeeking = NO;
}
if(moviePlayerController.playbackState == MPMoviePlaybackStatePaused)
{
if (self.movieWasPaused)
{
[self.bookmarkTimer invalidate];
self.bookmarkTimer = nil;
self.movieWasPaused = NO;
}
else
{
self.bookmarkTimer = [NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(checkToSetBookmark:) userInfo:nil repeats:NO];
self.movieWasPaused = YES;
}
}
if(moviePlayerController.playbackState == MPMoviePlaybackStateSeekingForward)
{
self.movieIsSeeking = YES;
}
if (moviePlayerController.playbackState == MPMoviePlaybackStateSeekingBackward)
{
self.movieIsSeeking = YES;
}
}
Upvotes: 0