Loading issues with AVPlayerItem from local URL

Deadly 提交于 2019-12-05 04:49:33

问题


I am working on a custom video player using AVPlayer. I load videos stored on the local file system in the Cache folder (NSCache). I initialize the player like this:

self.playerItem = [[AVPlayerItem alloc] initWithURL:self.localURL];
[self.playerItem addObserver:self forKeyPath:NSStringFromSelector(@selector(status)) options:NSKeyValueObservingOptionInitial context:nil];
self.avPlayer = [[AVPlayer alloc]initWithPlayerItem:self.playerItem];
[self.avPlayer addObserver:self forKeyPath:NSStringFromSelector(@selector(status)) options:NSKeyValueObservingOptionInitial context:nil];

This generally works fine. However I have frequent fails on the status of the AVPlayerItem with this error:

NSLocalizedDescription = "The operation could not be completed";
NSLocalizedFailureReason = "An unknown error occurred (-12983)";
NSUnderlyingError = "Error Domain=NSOSStatusErrorDomain Code=-12983

The strange thing is that the same URLs which fail sometimes work just shortly after and before such fails. I would say every 10th load attempt fails. I can't figure out what causes this or where to look for answers. A search for the error code turned up empty for me. Any help or pointers are highly appreciated.


回答1:


After a lengthy hunt, I was able to track down the source of the issue. The problem was an undocumented limit on the number of AVPlayer items which can exist concurrently. If there are too many instances videos can no longer be loaded failing with the AVPlayerItem error -12983.

Other people seem to have run into the same issue as well: AVPlayerItemStatusFailed error when too many AVPlayer instances created. I solved the issue by reusing player instances and making sure that there are not too many active ones at the same time.



来源:https://stackoverflow.com/questions/34541105/loading-issues-with-avplayeritem-from-local-url

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