也許有點晚了你的問題,但我發現了另一個原因來解釋這種現象:
每次嘗試FWD MPMoviePlaybackStateSeekingForward(4)或時間RWD MPMoviePlaybackStateSeekingBackward(5)之前有一個MPMoviePlaybackStatePaused(2)和一個MPMoviePlaybackStatePlaying(1)。因此,您可以在事件前後輕鬆跟蹤[MPMoviePlayerController currentPlaybackTime],並檢查它是否有暫停(兩者值相同),fwd(最初的<)或rwd(初始>最終)。
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;
}
需要一點點浮輪,因爲我發現暫停的時間有幾毫秒的不同。
是的,它有點遲了,但你的解決方案是好的。謝謝。 – 2011-12-23 21:32:49
這個解決方案的一個問題是,它不區分用戶實際點擊暫停按鈕的時間和用戶點擊「完成」按鈕的時間。點擊完成觸發暫停,然後停止。 – 2013-08-13 17:55:38