我已经为playbackLikelyToKeepUp 和playbackBufferEmpty 实现了KVO,并且还为AVPlayerItemPlaybackStalledNotification 通知添加了一个观察者。
我正在使用 Buffer Empty 和 Keep up 事件来显示/隐藏我的缓冲活动指示器,如果我收到 Playback Stalled 通知,我会在播放器上显示一条错误消息,直到我让 Keep Up 事件返回 true;我注意到有时在停顿后,缓冲区不会尝试恢复播放。此外,寻找播放头将解决此问题。
播放器有什么方法可以自动保持缓冲,或者让我知道缓冲是否完全停止并且不会继续尝试播放?
我已经对日志进行了注释以显示此功能。
**APP HITS LOW BANDWIDTH STALL NOTIFICATION GOES OUT
2014-11-22 09:09:16.887 SampleApp[216:60b] Playback Stall Notification: Show Error Slate
2014-11-22 09:09:29.072 SampleApp[216:60b] Playback Buffer Event: Buffer Empty - False
2014-11-22 09:09:29.373 SampleApp[216:60b] Playback Buffer Event: Playback Likely to keep up - True (If showing, hide error)
2014-11-22 09:09:44.466 SampleApp[216:60b] Playback Buffer Event: Playback Likely to keep up - False
**VIDEO PLAYBACK RESUMES
2014-11-22 09:09:44.468 SampleApp[216:60b] Playback Buffer Event: Buffer Empty - True
2014-11-22 09:09:45.839 SampleApp[216:60b] Playback Buffer Event: Buffer Empty - False
2014-11-22 09:09:47.582 SampleApp[216:60b] Playback Buffer Event: Playback Likely to keep up - True (If showing, hide error)
**VIDEO HAS JUST BEEN SEEKED FORWARD
2014-11-22 09:10:03.556 SampleApp[216:60b] Playback Buffer Event: Playback Likely to keep up - False
2014-11-22 09:10:03.558 SampleApp[216:60b] Playback Buffer Event: Buffer Empty - True
**PLAY BACK STALLS BUFFER MAKES NO ATTEMPT TO RESUME -- LOGS GENERATED BY HITTING PLAY BUTTON
2014-11-22 09:10:03.560 SampleApp[216:60b] Playback Stall Notification: Show Error Slate
2014-11-22 09:10:25.491 SampleApp[216:60b] Playback Buffer Event: Playback Likely to keep up - False
2014-11-22 09:10:25.494 SampleApp[216:60b] Playback Buffer Event: Buffer Empty - True
2014-11-22 09:10:25.495 SampleApp[216:60b] Playback Stall Notification: Show Error Slate
2014-11-22 09:10:27.302 SampleApp[216:60b] Playback Buffer Event: Playback Likely to keep up - False
2014-11-22 09:10:27.304 SampleApp[216:60b] Playback Buffer Event: Buffer Empty - True
2014-11-22 09:10:27.305 SampleApp[216:60b] Playback Stall Notification: Show Error Slate
2014-11-22 09:10:52.266 SampleApp[216:60b] Playback Buffer Event: Playback Likely to keep up - False
2014-11-22 09:10:52.269 SampleApp[216:60b] Playback Buffer Event: Buffer Empty - True
2014-11-22 09:10:52.270 SampleApp[216:60b] Playback Stall Notification: Show Error Slate
2014-11-22 09:10:53.521 SampleApp[216:60b] Playback Buffer Event: Playback Likely to keep up - False
2014-11-22 09:10:53.523 SampleApp[216:60b] Playback Buffer Event: Buffer Empty - True
2014-11-22 09:10:53.525 SampleApp[216:60b] Playback Stall Notification: Show Error Slate
2014-11-22 09:10:57.542 SampleApp[216:60b] Playback Buffer Event: Playback Likely to keep up - False
2014-11-22 09:10:57.545 SampleApp[216:60b] Playback Buffer Event: Buffer Empty - True
**I'VE MOVED THE PLAYHEAD UP SLIGHTLY AND THE BUFFERING EVENTS AND PLAYBACK HAVE RETURNED
2014-11-22 09:10:58.817 SampleApp[216:60b] Playback Buffer Event: Buffer Empty - False
2014-11-22 09:10:59.502 SampleApp[216:60b] Playback Buffer Event: Playback Likely to keep up - True (If showing, hide error slate)