AVplayerItem isPlaybackLikelyToKeepUp但不是真的,视频停止缓冲

时间:2017-07-03 19:35:37

标签: avfoundation avplayer avplayerviewcontroller avplayeritem

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    self.isPlayerReady(self.playerViewController?.player)

    if keyPath == #keyPath(AVPlayerItem.isPlaybackBufferEmpty){
        print("empty listener")
    }

    if keyPath == #keyPath(AVPlayerItem.isPlaybackLikelyToKeepUp){
        print("keepup change \(String(describing: playerViewController?.player?.currentItem?.isPlaybackLikelyToKeepUp))")
        if (playerViewController?.player?.currentItem?.isPlaybackLikelyToKeepUp == true) {
            print("tried to play")
                self.playerViewController?.player?.play()
                print( self.playerViewController?.player?.reasonForWaitingToPlay)
                print("buffer empty? \(self.playerViewController?.player?.currentItem?.isPlaybackBufferEmpty)")
                print("player rate \(self.playerViewController?.player?.rate)")
                print(self.playerViewController?.player?.currentItem?.error)

       }
   }
}

我将上面的观察者添加到playerItem,我发现当缓冲区持续时间仅为4或5时它很早就显示出PlayerItemlikelyToKeepup。当它试图播放时,它会停留在黑屏中而不再显示缓冲区将加载,因为观察者没有得到任何加载范围更新。而且ForWaitingToPlay是AVPlayerWaitingToMinimizeStallsReason。

我该如何避免这种状态?非常感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

尝试设置- hosts: appserver become: true become_method: su tasks: shell: /some_script/stop_application.ksh tags: - stop_app - hosts: dbserver become: true become_method: su become_user: oracle tasks: shell: /some_script/stop database_instance_name tags: - stop_db - hosts: dbserver become: true become_method: su become_user: oracle tasks: shell: /some_script/start database_instance_name tags: - start_db - hosts: appserver become: true become_method: su tasks: shell: /some_script/start_application.ksh tags: - start_app