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
I initially initialized an AVPlayerItem inside a cell and added it to an AVPlayer (also inside the cell). I later presented a new vc and passed over that same cell's AVPlayerItem to a different AVPlayer inside the new vc and got a crash. To fix it I just made a copy of the playerItem using .copy() as? AVPlayerItem
. A copy gives the new copy a different memory address from the original.
cell:
var cellPlayer: AVPlayer?
var cellsPlayerItem: AVPlayerItem?
cellsPlayerItem = AVPlayerItem(asset: AVAsset(url: url)) // cellsPlayerItem's memory address 0x1111111
cellPlayer = AVPlayer(playerItem: cellsPlayerItem!)
presented vc:
var vcPlayer: AVPlayer?
let playerItemCopy = cellsPlayerItem.copy() as? AVPlayerItem // playerItemCopy's memory address 0x2222222
let vcPlayer = AVPlayer(playerItem: playerItemCopy)