AVPlayer失败,AVPlayerItemStatusFailed(OSStatus错误-12983)

有时,AVPlayer失败, AVPlayerItemStatusFailed失败,AVPlayer继续失败, AVPlayerItemStatusFailed 。 我试图清除AVPlayer实例并创build一个新的,但我不能实现AVPlayerItemStatusFailed失败解决。 此外,使用AVPlayer实例removingFromSuperview UIView并使用AVPlayer初始化新项目并不能解决问题。

所以我想,AVPlayer不能完全清除。 有没有人build议尝试彻底清除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]; 

问题是这条线是无条件的:

 [self.layer addSublayer:avPlayerLayer]; 

因此,您每次都添加一个新的播放器图层。 因此,你正在堆放很多玩家图层。 这是错误的。 一定只有一个。 在添加播放器图层之前,请保留对旧播放器图层的引用并将其删除,或者,如果这是与以前相同的播放器,并且已经在该接口中具有关联的播放器图层,则不执行任何操作。

playerItem = nil创build一个AVPlayer的sharedInstance。 下次只replaceThePlayerItem。