UIScrollView中的多个AVPlayers - 仅显示其中的16个 [英] Multiple AVPlayers in a UIScrollView - only 16 of them are shown

查看:87
本文介绍了UIScrollView中的多个AVPlayers - 仅显示其中的16个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个视频库,我有一个ScrollView,里面有多个视图,每个视图都有一个AVPlayer - 到目前为止,它是非常标准的。请注意,所有AVPlayer都预装了他们的视频,等待播放。

I'm developing a video gallery, I have a ScrollView with multiple views inside of it, each view has a single AVPlayer - so far it's pretty standard I guess. Note that all of the AVPlayers are pre-loaded with their video, waiting to be played.

当我在图库中有很多项目(视频)时,会出现问题。在任何给定时间 - 只显示其中的16个,从开始到结束,其余显示黑屏。
如果我正在撤销物品的顺序 - 显示新的另外16个,其余的则显示黑屏。

The problem occurs when I have many items (videos) in the gallery. At any given time - only 16 of them are shown, from start to end, the rest shows a black screen. If I'm reversing the order of the items - the other 16 from the new side are shown, and the rest shows a black screen too.

另外,如果我去另一个屏幕,然后回到画廊 - 一切都变黑了,没有任何显示。

Additionally, if I go to another screen and then come back to the gallery - everything becomes black and nothing shown.

如果我用随机颜色背景替换玩家每个视图 - 显示所有视图。所以我认为问题在于玩家而不是视图本身。

If i'm replacing the players with a random color background for each view - all of the views are shown. So I assume the problem is with the players and not with the views themselves.

根据Xcode我的应用只使用~7-10%CPU和~10-11 MB因此它看起来不像是一个性能问题 - 更像是并发有效AVPlayers的限制,但我找不到任何有关它的信息。

According to Xcode my app only use ~7-10% CPU and ~10-11 MB of RAM so it doesn't looks like a performance problem - more like a limitation of concurrent active AVPlayers but I couldn't find any information regarding that.

有没有人有有什么建议么?这让我发疯了。

Does anyone have any suggestions? this is driving me crazy.

提前致谢!

推荐答案

我在不同的环境中遇到了与你相同的问题(我有一个加载视频的tableview,它在16次点击后停止工作)。

I was running into the same problem as you in a different context (I had a tableview that loaded a video and it stopped working after 16 clicks).

这些是一些帮助我的线程:

These were some of the threads that helped me out:

多次播放后AVPlayer崩溃 -

AVPlayerItem失败,AVStatusFailed和错误代码无法解码

如何关闭以前的AVPlayer和AVPlayerItem

Impos可以阻止AVPlayer

基本上可以创建16个avplayers / avplayerlayers的硬限制。如果你试图超过这个,你会得到不稳定的行为。

Essentially theres a hard limit of 16 avplayers/avplayerlayers that can be created. If you try to exceed this you get wonky behaviour.

在您的特定情况下,您必须创建一个包含16个视频的缓冲区并删除/添加它们,因为它们在滚动视图中不再可见。我建议将缓冲区降低(如8)导致16导致最新的iphone型号出现严重滞后。

In your particular case you will have to create a buffer of 16 videos and remove/add them as they no longer become visible on the scrollview. I would recommend making the buffer lower (like 8) cause 16 causes some serious lag on the latest iphone model.

要删除播放器,请使用以下代码:

To remove the player use this code:

player.pause()
player = nil
playerLayer.removeFromSuperlayer()

确保播放器是一个变量(不要使用let)并且它是一个可选类型。

Make sure the player is a variable (dont use let) and that it is an optional type.

var player : AVPlayer?  = AVPlayer(url: videoURL as URL)

希望这会有所帮助

这篇关于UIScrollView中的多个AVPlayers - 仅显示其中的16个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆