views:

1103

answers:

4

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  A: 

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.

subjective-c
A: 

Did anyone tried this on OS 3.0 (I don't have it yet)?

I have practically finished my application and this was the last thing I coded in and man, what a setback. :(

Aleksandar Vacic
+4  A: 

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.

Aleksandar Vacic
A: 

the App AddMusic freezes when choosing a title anyone having the same problem?

Menschel