美文网首页
判断avplayer 播放状态

判断avplayer 播放状态

作者: revivefsd | 来源:发表于2018-12-31 17:03 被阅读180次
             //监听 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"];
        }
    

    相关文章

      网友评论

          本文标题:判断avplayer 播放状态

          本文链接:https://www.haomeiwen.com/subject/odkwlqtx.html