1

My app needs to play some audio files and I want to fade-out the iPod sound, play my file, and then as soon as my audio stops playing fade-in iPod again (just like iPhone handles iPod music when an incoming call comes in)

I'm setting up my app's Audio Session to be kAudioSessionCategory_MediaPlayback and then just before I play my file I call AudioSessionSetActive (true) then when my file ends playing I call AudioSessionSetActive (false)

What happens is that the iPod audio fades-out with the AudioSessionSetActive (true) call, but it never fades-in again after I call AudioSessionSetActive (false)

I'm using AVFoundation class to play my audio, I audioPlayerDidFinishPlaying in my delegate method and that's where I call AudioSessionSetActive (false).

What am I missing here? Why doesn't the iPod fade-in when I deactive my audio session? Do I have the wrong Audio Session Category for this?

2 Answers 2

4

Ok, this is lovely. In iPhone OS3, see AddMusic example.

In essence, you do this:

#import <MediaPlayer/MediaPlayer.h>
...
[[MPMusicPlayerController iPodMusicPlayer] pause]
...(play your audio, with AmbientSound category)
[[MPMusicPlayerController iPodMusicPlayer] play]

This is basic. You can also add fadeout by looping volume change etc.

2

I got an answer from Apple about this. Unfortunately, it is not possible with SDK 2.2. I submitted a feature request, so who knows maybe the add this functionality in the future.

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.