如何在MPMoviePlayer类的currentPlaybackTime属性上添加KVO?
由于currentPlaybackTime属性未明确声明为KVO兼容,因此无法向其添加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;
}
}