//监听 timeControlStatus
[self.player addObserver:self forKeyPath:@"timeControlStatus" options:NSKeyValueObservingOptionNew context:nil];
////监听 timeControlStatus 播放状态,播放中允许旋转屏幕
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary<NSKeyValueChangeKey,id> *)change
context:(void *)context
{
if (object == self.player && [keyPath isEqualToString:@"timeControlStatus"]) {
if (@available(iOS 10.0, *)) {
AVPlayerTimeControlStatus status = [[change objectForKey:NSKeyValueChangeNewKey]integerValue];
if (status == AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate) {
// do something
}
} else {
// Fallback on earlier versions
// ios10.0之后才能够监听到暂停后继续播放的状态,ios10.0之前监测不到这个状态
//但是可以监听到开始播放的状态 AVPlayerStatus status监听这个属性。
}
}
}
//删除监听器
if (self.player) {
[self.player removeObserver:self forKeyPath:@"timeControlStatus"];
}
网友评论