'An AVPlayerItem cannot be associated with more than one instance of AVPlayer'

前端 未结 6 1244
醉酒成梦
醉酒成梦 2020-12-21 11:20

I know this question is all over Stack Overflow but still, most of them are old and not related with what I\'m going to ask here.

So I\'ve got an array with AV

6条回答
  •  [愿得一人]
    2020-12-21 11:51

    Using this code solved the problem for me:

    player?.pause()                     
    let playerItem = AVPlayerItem(asset: myAsset) 
    player = nil 
    player = AVPlayer()
    player?.replaceCurrentItem(with: playerItem)
    

    Instead of:

    player?.pause()                     
    player = nil player = AVPlayer()
    player?.replaceCurrentItem(with: availablePlayerItem) //
    availablePlayerItem is a playerItem which has been created before and
    played once with this AVPlayer
    

    Note: In both codes, the "player" is a global variable in my class which is:

    var player : AVPlayer? = nil

提交回复
热议问题