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.
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 log:
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. For @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];
filePath.path
is bad? Maybe coming out nil? – Dorkus