有时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)}
Run Code Online (Sandbox Code Playgroud)
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]; …
Run Code Online (Sandbox Code Playgroud)