0

I have an AVQueuePlayer which loads URLs to play audio files and it works well for the most part. However, I have run into a problem where after the player finishes playing a file (with another file in the queue), it will simply stop playing. Normally, the app would be able to use the player's rate, status, and items. In this case, I have gone through with the debugger and everything looks normal.

Everything appears to be playing, except for the player itself. After forcing the player to play, the player will skip to the next track, indicating that the AVPlayerItem it had was not loaded (I can confirm the audio urls are valid).

Does anyone have any ideas how I catch this programatically?

loadedion
  • 2,217
  • 19
  • 41

1 Answers1

0

You need to have the delegate method:

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag;

Once this method is finished, start the new audio.

random
  • 8,568
  • 12
  • 50
  • 85
  • The app is registered for the `AVPlayerItemDidPlayToEndTimeNotification` notification. However, I don't force any playback in this instance, but only remove the player's current item (the file which just finished). The `AVQueuePlayer` will continue playing any items in its queue. – loadedion Jan 22 '14 at 18:46
  • `AVPlayerItemDidPlayToEndTimeNotification` can post of a different thread than the one thread it was registered on. Have you checked this? – random Jan 22 '14 at 18:50
  • I haven't checked it, but would it be relevant in this case? The audio player is thread safe and is contained in a singleton class. – loadedion Jan 22 '14 at 19:17
  • Hmm I guess not, is the above delegate method called when `AVPlayerItemDidPlayToEndTimeNotification` is fired? – random Jan 22 '14 at 19:47
  • I haven't implemented `audioPlayerDidFinishPlaying`, but I believe it wouldn't be triggered, as it's for the `AVAudioPlayer`. I'm beginning to think that the `AVPlayerItem` which is queued in the player might be the cause of the problem here. After manually pressing play, there is an immediate `AVPlayerItemDidPlayToEndTimeNotification` notification. Although the media URLs are valid, they expire after about a minute. The files are tiny, and should begin buffering immediately after the `AVPlayerItem` is created, but that assumption may be suspect. – loadedion Jan 22 '14 at 21:11