如何将KVO添加到MPMoviePlayer currentPlaybackTime?

时间:2011-04-26 13:44:30

标签: iphone mpmovieplayercontroller observer-pattern key-value-observing

如何将KVO添加到MPMoviePlayer类的currentPlaybackTime属性中?

1 个答案:

答案 0 :(得分:14)

您无法将KVO添加到currentPlaybackTime,因为该属性未显式声明为KVO兼容。

相反,您可以尝试定期轮询播放器并存储位置,例如:

- (void) BeginPlayerPolling {
self.pollPlayerTimer = [NSTimer scheduledTimerWithTimeInterval:5
                                                       target:self 
                                                     selector:@selector(PollPlayerTimer_tick:)
                                                     userInfo:nil 
                                                      repeats:YES];  

}

- (void) PollPlayerTimer_tick:(NSObject *)sender {
// Store current playback position
if (player.playbackState == MPMoviePlaybackStatePlaying)
    lastRecordedPlaybackTime = player.currentPlaybackTime;
}

- (void) EndPlayerPolling {
if (pollPlayerTimer != nil)
{
    [pollPlayerTimer invalidate];
    self.pollPlayerTimer = nil;
}
}