有时 AVPlayer 失败AVPlayerItemStatusFailed
并在该失败发生后, AVPlayer 继续失败并出现AVPlayerItemStatusFailed
. 我试图清除 AVPlayer 实例并创建一个新实例,但我AVPlayerItemStatusFailed
无法解决失败。同样removingFromSuperview
UIView
使用 AVPlayer 实例并使用 AVPlayer 初始化新项目也不能解决问题。
所以我发现 AVPlayer 无法完全清除。有没有人建议尝试完全清除 AVPlayer 并使其在失败后工作?
错误日志:
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];