Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crash in -[AVPlayerItem _attachToPlayer:] An AVPlayerItem cannot be associated with more than one instance of AVPlayer

i got a crash affecting about 10% of my users, yet I'm unable to reproduce it, and don't know exactly when this happens.

Crashlytics reports about half of the crashing users having the App not in focus, I.e. doing background audio or AirPlay. The App plays back an HLS video stream, and switches to an audio only version when backgrounded.

Any ideas what's wrong, or why there would be multiple AVPlayer instances from my singleton Player class?

Thanks!

Exception Type:
NSInvalidArgumentException
Reason:
An AVPlayerItem cannot be associated with more than one instance of AVPlayer
Fatal Exception
Latest Crash: 4/06/2013 at 8:48:46 UTC+0200
0   CoreFoundation  __exceptionPreprocess + 162
1   libobjc.A.dylib objc_exception_throw + 30
2   AVFoundation    -[AVPlayerItem _attachToPlayer:] + 188
3   AVFoundation    -[AVPlayer _attachItem:andPerformOperation:withObject:] + 336
4   AVFoundation    -[AVPlayer _insertItem:afterItem:] + 26
5   AVFoundation    -[AVQueuePlayer insertItem:afterItem:] + 136
6   MediaPlayer __block_global_4 + 520
7
...
libdispatch.dylib   _dispatch_call_block_and_release + 10
14
like image 314
THM Avatar asked Apr 25 '13 11:04

THM


3 Answers

It seems to be solved by explicitly stopping the playing before setting a new URL, e.g.

[moviePlayer stop];
moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[moviePlayer setContentURL:[NSURL URLWithString:[videos objectForKey:quality]]];
like image 138
cujo30227 Avatar answered Nov 13 '22 19:11

cujo30227


Found the cause for this issue ... If MovieViewController was created, and it's currently buffering (i.e state != MPMovieLoadStatePlayable or MPMovieLoadStatePlaythroughOK) calling 'play' method will crash the app with this exception.

like image 24
Cherpak Evgeny Avatar answered Nov 13 '22 19:11

Cherpak Evgeny


Try to set the ContentURL after the SourceType

moviePlayerController_ = [[MPMoviePlayerViewController alloc] init];
moviePlayerController_.movieSourceType = MPMovieSourceTypeStreaming;
[moviePlayerController_.moviePlayer setContentURL:url];
like image 1
Hsm Avatar answered Nov 13 '22 17:11

Hsm