如何将KVO添加到MPMoviePlayer类的currentPlaybackTime属性?
最佳答案
您不能将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;
}
}