我正在寻找一种方法,以便在发生时准确收到通知AVPlayer
开始播放。有“费率”属性,但目前我正在定期检查它NSTimer
获取更新。
我尝试了 KVO,但显然它不符合 KVO 标准。
我知道有events https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html当玩家ENDED https://stackoverflow.com/questions/5655864/check-play-state-of-avplayer。但我在这里谈论的是暂停。
我还订阅了 KVOAVPlayerItem's
“状态”,但它向我显示 HTTP 资源何时完成缓存,没有播放/暂停。我还开始收集所有播放/暂停的调用,然后请求即时 UI 更新,但之前需要更多的运行循环AVPlayer
真的开始玩了。我只是想更新我的按钮即刻.
为什么说“率”不是KVO的抱怨呢?
这个对我有用。
这是我所做的:
- (void)viewDidLoad
{
...
[self.player addObserver:self forKeyPath:@"rate" options:0 context:nil];
}
进而:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"rate"]) {
if ([self.player rate]) {
[self changeToPause]; // This changes the button to Pause
}
else {
[self changeToPlay]; // This changes the button to Play
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)