Does setting the AVPlayerItem after creating the AVPlayer increase efficiency in iOS 13?

删除回忆录丶 提交于 2020-06-29 04:45:34

问题


In a WWDC 2016 video, Apple says create the AVPlayer without an AVPlayerItem, create the AVPlayerLayer, and then assign the AVPlayerItem to the AVPlayer.

I got the above code from @matt's Programming iOS 10 book. In it he says:

Apparently there is some sort of efficiency if you do things in this order. The reason, it turns out, is that when an AVPlayerItem is assigned to an AVPlayer that doesn't have and associated AVPlayerLayer, the AVPlayer assumes that only the audio track of the AVAssest is important -and then, when an AVPlayerLayer is assigned, it must scramble to pick up the video tracks as well

Even though that was iOS 10, does that efficiency still stand for iOS 13?

do it this way:

let asset = AVAsset(url: url)
let item = AVPlayerItem(asset: asset)
let player = AVPlayer()
let layer = AVPlayerLayer(player: player)
player.replaceCurrentItem(with: item) // playerItem set here

don't do it this way:

let asset = AVAsset(url: url)
let item = AVPlayerItem(asset: asset)
let player = AVPlayer(playerItem: item) // playerItem set here
let layer = AVPlayerLayer(player: player)

来源:https://stackoverflow.com/questions/62489214/does-setting-the-avplayeritem-after-creating-the-avplayer-increase-efficiency-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!