実際には、長い時間の後に再開するとプレーヤーがリムボーになっていることを示していません。 (私のテストでは、この状況でAVPlayerItemから受け取ったメタがnullであることがわかりました)
とにかく..私はインターネットから集まったものから50〜60秒後に再開しようとすると、プレイヤーはバックグラウンドでバッファリングし続けます。停止機能はここで良いでしょう。
私の解決方法: それが50秒経過したかどうかを確認する単純なタイマーで、再開メソッドが呼び出されたときに新しいプレーヤーを開始することを知るフラグを更新します。
func pausePlayer() {
..
player.pause()
..
// Will count to default 50 seconds or the indicated interval and only then set the bufferedInExcess flag to true
startCountingPlayerBufferingSeconds()
bufferedInExcess = false
}
func startCountingPlayerBufferingSeconds(interval: Double = 50) {
timer = NSTimer.scheduledTimerWithTimeInterval(interval, target: self, selector: Selector("setExcessiveBufferedFlag"), userInfo: nil, repeats: false)
}
func setExcessiveBufferedFlag() {
if DEBUG_LOG {
print("Maximum player buffering interval reached.")
}
bufferedInExcess = true
}
func stopCountingPlayerBufferingSeconds() {
timer.invalidate()
}
func resumePlayer() {
if haveConnectivity() {
if (.. || bufferedInExcess) {
startPlaying(true)
} else {
..
player.play
}
..
}
}
func startPlaying(withNewPlayer: Bool = false) {
if (withNewPlayer) {
if DEBUG_LOG {
print("Starting to play on a fresh new player")
}
// If we need another player is very important to fist remove any observers for
// the current AVPlayer/AVPlayerItem before reinitializing them and add again the needed observers
initPlayer()
player.play()
...
}
...
}
ステータスチェックは、その60秒の遅延の後に行われると思います。 – sailens
はい正確に私はこれらの両方のチェックを60秒の休止の後に行います – turushan
私はこれがなぜ起こっているのか分かりません:S – sailens