Maintaining good scroll performance when using AVPlayer

后端 未结 6 1102
无人及你
无人及你 2020-11-30 17:34

I\'m working on an application where there is a collection view, and cells of the collection view can contain video. Right now I\'m displaying the video using AVPlayer

6条回答
  •  猫巷女王i
    2020-11-30 18:02

    I've played around with all the answers above and found out that they're true only to a certain limit.

    Easiest and the simplest way that worked for me so far is that the code you assign your AVPlayerItem to your AVPlayer instance in a background thread. I noticed that assigning the AVPlayerItem to the player on the main thread (even after AVPlayerItem object is ready) always takes a toll on your performance and frame rate.

    Swift 4

    ex.

    let mediaUrl = //your media string
    let player = AVPlayer()
    let playerItem = AVPlayerItem(url: mediaUrl)
    
    DispatchQueue.global(qos: .default).async {
        player.replaceCurrentItem(with: playerItem)
    }
    

提交回复
热议问题