views:

455

answers:

1

Hello. First, thanks for the StackOverflow team, cause it's a very useful website, since i'm developping on iPhone. Secondary, please excuse my language. I'm a frenchie and like every frenchies i'm very bad in english.

I've a very strange problem with my sounds in my iPhone program : I implemented a class which play a short sound in aiff. Here it is :

@implementation SoundPlayer

-(id)initWithFile:(NSString*)file{
    self = [super init];
    NSString *soundPath =  [[NSBundle mainBundle] pathForResource:file ofType:@"aiff"];
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
    return self;
}

-(void)play {
    if(SOUND_ACTIVATED){
     AudioServicesPlaySystemSound (soundID);
        }
}

-(void)dealloc{
    [super dealloc];
}

@end

It works quite good, but even if my instances are initialized the same way, they are not in the same audio stream !

I noticed that because when I push the volume+ and volume- buttons of the iPhone, in some cases it controls the main audio stream, in other cases it controls the ring volume. If I put the main stream to volume 0, sound A won't be hearable, but sound B will be.

Did someone have a similar problem ? Do you have any idea ?

Thanks a lot.

Martin

+1  A: 

Ok. I found somehing that would be interesting to answer the problem. There's a global function which initialize the audio context. It seem's that I don't use it the right way, but I think the problem comes from there.

// Initialize the Audio context
AudioSessionInitialize (
    NULL,          // 'NULL' to use the default (main) run loop
    NULL,          // 'NULL' to use the default run loop mode
    NULL,          // a reference to your interruption callbac
    self           // data to pass to your interruption listener callback
);

// What kind of sound will be played
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (
    kAudioSessionProperty_AudioCategory,
    sizeof (sessionCategory),
    &sessionCategory
);

In spite of these two functions, one sound is remaining on the ring stream, and that's really strange. Can someone help me ?

Martin