AVPlayer “freezes” the app at the start of buffering an audio stream

后端 未结 3 1395
灰色年华
灰色年华 2020-12-12 12:52

I am using a subclass of AVQueuePlayer and when I add new AVPlayerItem with a streaming URL the app freezes for about a second or two. By freezing

3条回答
  •  青春惊慌失措
    2020-12-12 13:43

    Gigisommo's answer for Swift 3 including the feedback from the comments:

    let asset = AVAsset(url: url)
    let keys: [String] = ["playable"]
    
    asset.loadValuesAsynchronously(forKeys: keys) { 
    
            DispatchQueue.main.async {
    
                let item = AVPlayerItem(asset: asset)
                self.playerCtrl.player = AVPlayer(playerItem: item)
    
            }
    
    }
    

提交回复
热议问题