AVPlayer does not fire playbackBufferEmpty but does not play either

前端 未结 1 1763
没有蜡笔的小新
没有蜡笔的小新 2021-01-05 04:33

I use AVPlayer to play an audio livestream via internet. I like to recover playback if it was paused for longer than 1 minute.

I call player.rate = 1.0

相关标签:
1条回答
  • 2021-01-05 04:48

    Use the timeControlStatus of the AVPlayer instance which "indicates whether playback is currently in progress, paused indefinitely, or suspended while waiting for appropriate network conditions."

    let status = player.timeControlStatus
    
    switch status {
    case .paused:
        print("timeControlStatus.paused")
    
    case .playing:
        print("timeControlStatus.playing")
    
    case .waitingToPlayAtSpecifiedRate:
        print("timeControlStatus.waitingToPlayAtSpecifiedRate")
        if let reason = player.reasonForWaitingToPlay {
    
            switch reason {
            case .evaluatingBufferingRate:
                print("reasonForWaitingToPlay.evaluatingBufferingRate")
    
            case .toMinimizeStalls:
                print("reasonForWaitingToPlay.toMinimizeStalls")
    
            case .noItemToPlay:
                print("reasonForWaitingToPlay.noItemToPlay")
    
            default:
                print("Unknown \(reason)")
            }
        }
    
    }
    

    I have the same issue but in my case, it occurs if I go into background while in the paused state. When I come back to forground .play() does not work. It gets stuck the waitingToPlayAtSpecifiedRate.evaluatingBufferingRate mode. At that point the AVPlayerItem.status instance is readToPlay.

    At this time of writing whenever a startCommand is received I reset the AVplayer to be sure. But this seems clunky. Looking for a smoother solution.

    0 讨论(0)
提交回复
热议问题