6

I have an app that handles streaming video. Starting with a .m3u8 playlist, it creates an array of AVAssets, and flips through them by

[player replaceCurrentItemWithPlayerItem:[AVPlayerItem playerItemWithAsset:[assetItems objectAtIndex:index]]]

This works fine, but before that I want to air a short mp4 video using progressive downloading. I load the AVPlayer using

AVAsset *prerollAsset = [AVAsset assetWithURL:prerollURL];
[player replaceCurrentItemWithPlayerItem:[AVPlayerItem playerItemWithAsset:prerollAsset]];

It plays, but when I continue with the streaming video as before, I get a status of AVPlayerStatusFailed, with the error in AVPlayerItem of The operation could not be completed

For it to work, I need to create an AVPlayer object for the (progressive download) preroll, and then a completely new AVPlayer object to start playing the streaming video.

Is it possible that a single AVPlayer instance isn't capable of playing progressive download video followed by streaming video? Or might there be something else I am doing wrong?

coco
  • 2,998
  • 1
  • 35
  • 58
  • 1
    I'm having the same problem. With MPMoviePlayerController there's movieSourceType property that we can set but not with AVPlayer or AVPlayerItem – Kent Nguyen Jun 01 '12 at 18:25
  • This bug still exists on iOS7.1 SDK – Taher Saeed May 23 '14 at 18:41
  • @KentNguyen a little late, but you can read https://developer.apple.com/library/mac/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html, look at the part **To create and prepare an HTTP live stream for playback** – onmyway133 Sep 06 '14 at 14:14
  • @onmyway133 Note that we often don't have control over the format of what we are asked to play; for example, streaming content intercut with progressive downloaded advertisements. – coco Sep 10 '14 at 15:49
  • AVFoundationErrorDomain Code=-11800 with OSStatus error -12783 — did you have the same? I'd then leave it here to possibly save someone else from a day of googling. – Gleb A. Dec 07 '14 at 20:17
  • @GlebA. I'm getting AVErrorUnknown (-11800), with NSUnderlyingError of (NSOSStatusErrorDomain, code = -12783) when switching from MP3 to HLS, and without NSUnderlyingError when switching from HLS to MP3. And thank you, I wouldn't have found this question without you posting those numbers. :-) – Andrey Tarantsov Apr 13 '15 at 09:53

1 Answers1

2

This bug is a known issue, and purportedly fixed in the next major release of iOS.

In the interim, creating a new AVPlayer object is the only known workaround.

  • 1
    According to the Apple engineers at WWDC14, iOS 8 still has this problem. They also mentioned it was very low on their priority list. Back to the workaround! – coco Sep 10 '14 at 15:50