我正在尝试监控AvPlayerItem的播放速率。根据时基文档(https://developer.apple.com/documentation/avfoundation/avplayeritem/1387605-timebase),最好的方法是订阅kCMTimebaseNotification_EffectiveRateChanged通知。
所以我这样设置了观察者:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(timeBaseEffectiveRateChanged:) name:(__bridge NSString *)kCMTimebaseNotification_EffectiveRateChanged object:(__bridge id)(self.currentPlayer.currentItem.timebase)];
实现选择器只是记录该playerItem的速率:
- (void) timeBaseEffectiveRateChanged: (NSNotification *) pNotification{
if (self.currentPlayer && self.currentPlayer.currentItem && self.currentPlayer.currentItem.timebase) {
ASMELogDebug(@"into timeBaseEffectiveRateChanged to %f", CMTimebaseGetRate(self.currentPlayer.currentItem.timebase));
}else {
ASMELogDebug(@"into timeBaseEffectiveRateChanged. Something is not set");
}
}
我在日志记录中注意到timeBaseEffectiveRateChanged处理程序每秒被调用多次,并且时基的速率没有改变(它总是1.0000)。
如何正确使用此通知,以便仅在playerItem的比率实际发生变化时调用?