如何将KVO添加到MPMoviePlayer currentPlaybackTime? [英] How to add a KVO to MPMoviePlayer currentPlaybackTime?
本文介绍了如何将KVO添加到MPMoviePlayer currentPlaybackTime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将KVO添加到MPMoviePlayer类的currentPlaybackTime属性中?
How can I add a KVO to the currentPlaybackTime property of a MPMoviePlayer class?
推荐答案
您不能将KVO添加到currentPlaybackTime中,因为该属性未明确声明为与KVO兼容.
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;
}
}
这篇关于如何将KVO添加到MPMoviePlayer currentPlaybackTime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文