13

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
4
  • 1
    Maybe the crashing is happening when trying to reconnect after a drop or low connectivity?
    – neowinston
    Apr 26, 2013 at 12:28
  • Seeing this same issue in our app in Crashlytics, haven't tracked down the problem. It's one of our top iOS 7 crashes and for us 97% of users have the app in focus.
    – ToddH
    Oct 10, 2013 at 19:06
  • We're also seeing thousands of crashes with the same log. Since we don't have any movie players in our app, it happens when users watch movies in an in-app browser. We THINK we have tracked the problem down to videos that displays ads before the video (for example DailyMotion) and then the crash happens when it switches from the ad player to the actual player. We haven't been able to fix it since it's not in our code. I think it's an iOS7 bug.
    – Accatyyc
    Oct 31, 2013 at 9:37
  • @THM did you have any luck with this? I facing the same issue
    – FabKremer
    Dec 11, 2015 at 13:34

5 Answers 5

5

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

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.

1
  • I updated the app to only call play when not buffering, but the crashes still come in, still cannot reproduce myself.
    – THM
    Aug 21, 2013 at 13:16
1

Try to set the ContentURL after the SourceType

moviePlayerController_ = [[MPMoviePlayerViewController alloc] init];
moviePlayerController_.movieSourceType = MPMovieSourceTypeStreaming;
[moviePlayerController_.moviePlayer setContentURL:url];
0

If you are not sure type of video URL you are going fetch set source type to Unknown. This will work for all cases.

moviePlayerController = [[MPMoviePlayerViewController alloc] init];
moviePlayerController.movieSourceType = MPMovieSourceTypeUnknown;
[moviePlayerController.moviePlayer setContentURL:url];
0

Couple of things to consider:

  1. A proxy between the player item and the player would provide a means to control access to the player item by instances of AVPlayer.

  2. Associated references enable storage of properties added to a given class via a category; so, you could create a category for the player item class that consists of a single property that is set whenever the player item is assigned to an AVPlayer (it's description string, for example). To ensure that the player item is not assigned to another player, simply compare the description stored with the AVPlayer to the one returned by the player in question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.