Josh Kahane
Josh Kahane

Reputation: 17169

AudioServicesPlaySystemSound Volume?

I have this code:

-(void)createAndPlaySoundID: (NSString*)name 
{
    NSString *path = [NSString stringWithFormat: @"%@/%@", [[NSBundle mainBundle] resourcePath], name];
    
    NSURL* filePath = [NSURL fileURLWithPath: path isDirectory: NO];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
    
    AudioServicesPlaySystemSound(soundID);
}

I call this like so:

[self createAndPlaySoundID: @"mySound.caf"];

This works great, however I have no control over the volume. I simply want the volume to be controlled by the user using the standard physical volume buttons on their iPad.

If I put this volume down to say 1, it plays, great, but then if I whack the device volume up to max its the same volume.

Upvotes: 21

Views: 15449

Answers (1)

Jon Brooks
Jon Brooks

Reputation: 2492

I was also bit by a similar problem on this topic.

My problem was that there was a global setting that I was unaware of.

In the Settings app, under

General > Sounds > Ringer and Alerts

If 'Change with Buttons' is set to Off, then sounds using AudioServicesPlaySystemSound() will always be played at full volume (yet other sound API's such as AVAudioPlayer will respect the volume of the device).

Upvotes: 35

Related Questions