How to add a KVO to MPMoviePlayer currentPlaybackTime?

被刻印的时光 ゝ 提交于 2019-12-12 08:48:26

问题


How can I add a KVO to the currentPlaybackTime property of a MPMoviePlayer class?


回答1:


You cannot add a KVO to currentPlaybackTime since the property is not explicitly declared as KVO compatible.

Instead, you could try polling the player regularly and storing the position, with code such as:

- (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;
}
}


来源:https://stackoverflow.com/questions/5791273/how-to-add-a-kvo-to-mpmovieplayer-currentplaybacktime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!