创建过多AVPlayer实例时AVPlayerItemStatusFailed错误

编程入门 行业动态 更新时间:2024-10-26 04:31:32
本文介绍了创建过多AVPlayer实例时AVPlayerItemStatusFailed错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个iOS应用程序,该应用程序会创建用户池提交的所有视频的供稿,使用户能够浏览和查看其他人创建的视频。您可以想象,我需要能够在Feed中支持任意数量的视频。

I'm working on an iOS app which creates a feed of all the videos submitted by the pool of users, enabling users to browse and view the videos that others have created. As you can imagine, I need to be able to support an arbitrary number of videos in the feed.

目前,我正在为每个视频创建并保留一个AVPlayer实例,如下所示:

Currently, I am creating and retaining an AVPlayer instance for each video like so:

//inside the init method of a UIView //create the AVPlayer and store it in a strong property NSString * urlString = @"aRemoteURL.mov"; NSURL * movURL = [NSURL URLWithString:urlString]; _videoPlayer = [[AVPlayer alloc]initWithURL:movURL]; //register callbacks for handling buffering [_videoPlayer.currentItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil]; [_videoPlayer.currentItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil]; //add the AVPlayerLayer to the view so you can see the video AVPlayerLayer * playerLayer = [AVPlayerLayer playerLayerWithPlayer:_videoPlayer]; playerLayer.frame = self.frame; [self.layer addSublayer:playerLayer];

我在<$ c $上打电话播放 c> _videoPlayer 当用户点击 UIView 时,一切正常。也就是说,直到有足够的视频提交到Feed ...

I call play on _videoPlayer when the user taps on the UIView, and everything works perfectly. That is, until enough videos are submitted to the feed...

Feed中存在超过18个视频, AVPlayer的新实例将无法播放, _videoPlayer.currentItem.status 将出现 AVPlayerItemStatusFailed ,且出现模糊错误代码= -11800操作无法完成。有趣的是,无论前18个视频的长度和质量如何,它始终是第19个视频,它是第一个打破的。

Once more than 18 videos exist in the feed, the new instances of AVPlayer will not play, and _videoPlayer.currentItem.status will be AVPlayerItemStatusFailed with an ambiguous error Code=-11800 "The operation could not be completed". Interestingly, it is always the 19th video which is the first to break, regardless of the length and quality of the first 18 videos.

我认为我不应该这样做要创建所有这些AVPlayer实例。我尝试使用AVPlayer单例包装器,当用户想要播放视频时,我将共享的AVPlayer实例传递给相关的UIView。这消除了 AVPlayerItemStatusFailed 错误,但使播放显着滞后。

I take it I'm not supposed to be creating all these AVPlayer instances. I tried using an AVPlayer singleton wrapper, where I handed a shared AVPlayer instance around to the relevant UIView when a user wanted to play a video. This eliminated the AVPlayerItemStatusFailed error, but made playback unusably laggy.

我无法找到此问题的任何其他帐户。如果有人能够提供一些有关这种情况的更好方法的见解,或者甚至指向一个好的AVPlayer教程的方向,我将非常感激。谢谢!

I haven't been able to find any other accounts of this problem. If anyone can offer some insight into a better approach to this situation, or even so much as point me in the direction of a good AVPlayer tutorial, I will be very grateful. Thanks!

推荐答案

如果有人遇到同样的问题,我最终会创建一个解决方案。事实证明,AVPlayer实例的数量受到iPhone硬件的限制,我希望Apple能够更清楚地说明这一点。 这个问题涉及到这一点。

If anyone comes across this same problem, I ended up creating a work around. Turns out that the number of AVPlayer instances is limited by iPhone hardware, I wish Apple made this more clear. This question touches on that.

为了解决这个限制,我创建并保留 AVURLAsset 以及 AVPlayerItem 我希望播放的每个视频。在播放视频的时候,我动态创建一个 AVPlayer 实例(不是共享实例),添加 AVPlayerItem 播放,播放视频。视频播放完毕后,我会销毁 AVPlayer 实例以释放硬件。这对我和我的专业情况都很有效,但如果您遇到上述问题,这种情况的一些变化也会对您有所帮助。

In order to get around this limitation, I create and retain an AVURLAsset as well as an AVPlayerItem for each video I wish to play. When it's time to play the video, I create an AVPlayer instance on the fly (not a shared instance), add the AVPlayerItem to it, and play the video. After the video is done playing, I destroy the AVPlayer instance to free up the hardware. This is working well for me and my specialized situation, but some variation of this should help you too if you're experiencing the problem outlined above.

小咆哮:

在过去的几个月里,我一直在广泛地使用AVFoundation,以多种不同的方式操纵不同类型的媒体。我经常发现自己在诅咒Apple的骨架文档以及与AVFoundation框架相关的示例。我希望他们能够支持他们的文档,因为很多框架都是错综复杂且不直观的。这个小小的咆哮在互联网的尘土飞扬的角落里不会改变任何东西,但我想我只是在发泄。

I have been working fairly extensively with AVFoundation over the last couple of months, manipulating different types of media in lots of different ways. I frequently find myself cursing Apple's skeletal documentation and examples related to the AVFoundation framework. I wish they would bolster their docs for this as a lot of the framework is convoluted and unintuitive. This tiny rant in a dusty corner of the internet won't change anything but I guess I'm just venting.

end rant

更多推荐

创建过多AVPlayer实例时AVPlayerItemStatusFailed错误

本文发布于:2023-11-25 12:16:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629712.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实例   错误   AVPlayer   AVPlayerItemStatusFailed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!