views:

98

answers:

1

Hello everyone...

I ran audio in the background in my iPhone app using AVAudioPlayer and AVAudioSession...

Now my problem is that I already have a written code that takes a number of songs as input from the user and plays them one after the other using AVAudioPlayer...

The problem is that when the app goes to the background while one of the files is being played, the audio continues but when it's done, the sound disappears... In foreground when a file is done, I just do some code to play the next one but in the background this is not possible...

I thought about requesting some time to get this done and run my code but I can't do this as the audio files always change and they might be long... So please tell me what should I do? Is there any built-in playlist player that run as a background audio? or is there any other solution? I really need to get this into work...

thanks a lot

A: 

I ran into the same issue and haven't completely resolved it yet. The audioDidFinishPlaying delegate method still fires, and you can use UIAplication's beginBackgroundTask to create a new instance of AVaudioPlayer, make sure AVAudioSession is still active, etc. But when I try to play the new AVAudioPlayer instance, it pauses immediately. My suspicion/fear is that there is no way to start the audio FROM the background, only keep it playing when the application state transition happens. I'd love to be wrong, though.

toddheasley
Continuing to work on this problem, I noticed that the MPMoviePlayerController can be given a new URL without being destroyed and re-instantiated, so you keep the active audio session when running in the background. (And MPMoviePlayer works fine for just audio, despite its name.)
toddheasley