AVPlayer失败,出现AVPlayerItemStatusFailed(OSStatus错误-12983) [英] AVPlayer fails with AVPlayerItemStatusFailed (OSStatus error -12983)
问题描述
有时AVPlayer失败,并显示AVPlayerItemStatusFailed
,发生该故障后,AVPlayer继续失败,并显示AVPlayerItemStatusFailed
.我试图清除AVPlayer实例并创建一个新实例,但无法解决removingFromSuperview
UIView
并使用AVPlayer初始化新项目也不能解决问题.
Sometimes AVPlayer fails with AVPlayerItemStatusFailed
and after that failure occurred, AVPlayer continues to failed with AVPlayerItemStatusFailed
. I tried to clear the AVPlayer instance and create new one, but I cannot achieve AVPlayerItemStatusFailed
failure to solve. Also removingFromSuperview
UIView
with AVPlayer instance and initializing new item with AVPlayer does not solve the problem.
所以我发现无法完全清除AVPlayer.是否有人建议您尝试完全清除AVPlayer并使其在故障后起作用?
So I figured that out AVPlayer couldn't been cleared completely. Is there anybody suggest anything to try for clearing the AVPlayer completely and make it works after failure?
错误日志:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x1a689360 {NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x1a688e70 "The operation couldn’t be completed. (OSStatus error -12983.)", NSLocalizedFailureReason=An unknown error occurred (-12983)}
UPD. 对于@matt
playerItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:filePath.path]];
if (!self.avPlayer) {
avPlayer = [AVPlayer playerWithPlayerItem:playerItem];
}
[avPlayer.currentItem addObserver:self forKeyPath:@"status" options:0 context:nil];
if (self.avPlayer.currentItem != self.playerItem) {
[self.avPlayer replaceCurrentItemWithPlayerItem:playerItem];
}
AVPlayerLayer *avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
avPlayerLayer.frame = self.bounds;
[self.layer addSublayer:avPlayerLayer];
avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[avPlayer play];
推荐答案
问题是此行是无条件的:
The problem is that this line is unconditional:
[self.layer addSublayer:avPlayerLayer];
因此您每次都添加一个新的播放器层.因此,您要堆积许多播放器图层.这是错误的.只能有一个.保留对旧播放器层的引用,并在添加播放器层之前将其删除,或者,如果该播放器与以前的播放器相同,并且在界面中已经具有关联的播放器层,则不执行任何操作.
Thus you are adding a new player layer every time. Thus you are piling up many player layers. This is wrong. There must be only one. Keep a reference to the old player layer and remove it before adding a player layer, or, if this is the same player as before and it has the associated player layer in the interface already, do nothing.
这篇关于AVPlayer失败,出现AVPlayerItemStatusFailed(OSStatus错误-12983)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!