I need to use AVAudioPlayer and MPMoviePlayerController simultaneously i.e play a movie while the background loop is playing is it possible.
My bg music loop stops working when a movie starts playing , so I tried to stop the bg music loop and start the movie and when movie stops, start playing the bg loop again but this is also is not working.
-
Should this be done using AudioQueue if yes how? I am new to iPhone and understanding AudioQueue documentation is really difficult for me. – Rakesh.P Aug 10 '09 at 11:16
-
okay my mistake stopping and playing back AVAudioPlayer does work before starting and stopping of movie does work, but is it really not possible to use AVAudioPlayer and MPMoviePlayerController simultaneously if so why? – Rakesh.P Aug 25 '09 at 13:01
2 Answers
In fact it is achievable from 3.x onwards. I had once done this in one of my applications and its got nothing to do with any backgrounding or any other new iOS features. You just need to configure the audio sessions properly. If you make sure that both your audio player as well as the video player are using the ambient audio session it is possible.
Prior to starting your AVAudioPlayer
to play, set the category of audio session to AVAudioSessionCategoryAmbient
. This is the system wide common audio session. This allows other sounds to play along such as the sound from the iPod application.
In case you are using the MPMoviePlayerController
from iOS 3.2 or above make sure you set the useApplicationAudioSession
to NO
. This ensures other sounds to play along. It is the default in earlier versions of iOS.

- 21
- 2
-
1Hey, It worked Thanks. If anyone is wondering how to set audio session category use this. `[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];` – NSRover Jan 17 '12 at 07:00
There is a limitation in the current iPhone SDK (2.x and 3.x) that does not allow any background audio playing while a movie is playing in the MPMoviePlayerController API. Unfortunately, it is not possible to do what you are asking at this time within the iPhone SDK.
I would suggest logging an enhancement request to Apple to offer this in a future version of the SDK.

- 12,721
- 2
- 26
- 23