How many AVPlayers are allowed to be created at the same time?

走远了吗. 提交于 2020-01-11 02:26:07

问题


I have a collectionView and each cell has an AVPlayer which is set to play. So every cell is playing a video at the same time. It seems that iOS only allows you to play 16 videos at the same time. For example, look at my sample app below. Out of 50 cells, only 16 started playing a video. This number always stays the same. This happens on a iPhone 6s running iOS 10. In the Xcode simulator however all 50 videos start playing. This issue only happens on an actual device.

Also, I get these two errors when I print this out:

print("Video player Status Failed: player item error =  (self.player.currentItem.error)")
print("Video player Status Failed: player error = \(self.player.error)")

2016-11-07 15:53:46.548288 SampleApp[1810:515089] Video player Status Failed: player item error = Error Domain=AVFoundationErrorDomain Code=-11839 "Cannot Decode" UserInfo={NSUnderlyingError=0x1704414d0 {Error Domain=NSOSStatusErrorDomain Code=-12913 "(null)"}, NSLocalizedFailureReason=The decoder required for this media is busy., NSLocalizedRecoverySuggestion=Stop any other actions that decode media and try again., NSLocalizedDescription=Cannot Decode} 2016-11-07 15:53:46.548358 SampleApp[1810:515089] Video player Status Failed: player error = (null)

Is there a limit to how many AVPlayer's you could have or am I doing something wrong?

Thanks!


回答1:


Indeed, it's common knowledge that there's an upper limit on the amount of AVPlayer instances you can keep alive at the same time, but this limit depends on the platform your code is running on. I myself have found that on an iPhone 5s running iOS 8, there was a limit of 4 concurrent AVPlayer instances. Here, for example, the user reports a limit of 7 for tvOS, and the same limit of 4 was reported in 2012 in stack overflow.

In any case, this limit not being officially documented means it can change back and forth between platforms and OS versions, so you should not base any code on this other than just keep concurrent AVPlayer instances as low as possible.



来源:https://stackoverflow.com/questions/40474480/how-many-avplayers-are-allowed-to-be-created-at-the-same-time

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