AVPlayer fails with AVPlayerItemStatusFailed (OSStatus error -12983)

ぃ、小莉子 提交于 2020-01-01 08:43:13

问题


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];

回答1:


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.




回答2:


Create a sharedInstance of AVPlayer with playerItem = nil. Next time only replaceThePlayerItem.




回答3:


It sometimes happened in iOS simulator,
try to restart simulator again may will work. :)



来源:https://stackoverflow.com/questions/23850366/avplayer-fails-with-avplayeritemstatusfailed-osstatus-error-12983

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!