AVPlayer fails with AVPlayerItemStatusFailed (OSStatus error -12983)
Asked Answered
J

3

10

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];
Jacinto answered 24/5, 2014 at 22:46 Comment(4)
Show your code - the code that you use to try to play in the first place.Dorkus
@Dorkus Thanks for your answer, I added my code above.Jacinto
Any chance that filePath.path is bad? Maybe coming out nil?Dorkus
@Dorkus The link is always mp4 file, movie always plays on the Web and in the simulator, but not always on the device.Jacinto
D
8

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.

Dorkus answered 25/5, 2014 at 11:28 Comment(2)
Also make sure that you are not retaining any object of either AVPlayer, AVPlayerLayer or AVPlayerItem. In my case I was using [player addPeriodicTimeObserverForInterval:] to get periodic intervals. it was retaining AVPlayer. Instead i used an NSTimer and Invalidated it when requiredOrthorhombic
I use symbolic breakpoint to ensure that AVPlayer is deallocated properly, and I use only 1 instance of AVPlayerLayer, but that error happens after sometimes (iOS 8 has a bug that it does not resume player, so i must restart the player), why is thatDespotic
G
0

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

Gauhati answered 26/7, 2017 at 10:36 Comment(0)
L
-2

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

Louden answered 11/1, 2018 at 7:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.