AVPlayerItemStatus Error when too many AVPlayer instances occur

I’m working on an iOS application that feeds all videos submitted by a user pool, allowing users to view and view videos created by others. As you can imagine, I need to be able to support an arbitrary number of videos in the feed.

I am currently creating and saving an instance of AVPlayer for each video, for example:

//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];

I call playon _videoPlayerwhen the user clicks on UIViewand everything works fine. That is, until enough videos are sent to the channel ...

18 , AVPlayer , _videoPlayer.currentItem.status AVPlayerItemStatusFailed Code=-11800 "The operation could not be completed". , 19- , , 18 .

, AVPlayer. AVPlayer, AVPlayer UIView, . AVPlayerItemStatusFailed, .

. - , AVPlayer, . !

+4
1

- , . , AVPlayer iPhone, , Apple . .

, AVURLAsset, AVPlayerItem , . , AVPlayer " " ( ), AVPlayerItem . AVPlayer, . , , , .

:

AVFoundation , . , Apple , AVFoundation. , , . , , .

end rant

+9

Source: https://habr.com/ru/post/1618038/


All Articles