1

I'm trying to play a sound on top of the iPod music but when I enter my app the iPod sound is silenced automatically. I tried:

UInt32 sessionCategory = kAudioSessionCategory_AmbientSound; 
        AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,                                 
                                 sizeof (sessionCategory),
                                 &sessionCategory                                 
                                 );

But probably because I use RemoteIO/Audio Units to play my sound this has no effect (not sure if that's the cause, but it sure thing does nothing ... the sound still stops)

I am missing something?

Rad'Val
  • 8,895
  • 9
  • 62
  • 92

3 Answers3

3

For some reason, the code in the question doesn't work, however this works:

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
Rad'Val
  • 8,895
  • 9
  • 62
  • 92
1

AudioSessionSetProperty returns an error, are you checking it?

You may have forgotten to call AudioSessionInitialize, something you don't need to do with the AVFoundation wrapper.

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159
  • indeed, i didn't call `AudioSessionInitialize`, however, strange enough I checked at it returned no error, will choose your answer because it explains why the above code is not working – Rad'Val May 29 '11 at 14:12
0
@property (nonatomic, strong) AVAudioPlayer * avAudioPlayer;


NSString *zeroAudioPath = [[NSBundle mainBundle] pathForResource:@"customSound" ofType:@"wav"];
NSURL *file = [[NSURL alloc] initFileURLWithPath:zeroAudioPath];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:file
                                                                 error:nil];
self.avAudioPlayer = audioPlayer;
self.avAudioPlayer.delegate = self;
[_zeroAudioPlayer prepareToPlay];
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:&error];
[_zeroAudioPlayer play];

Hope it will help you.

Prabhat Pandey
  • 277
  • 10
  • 13