Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
638 views
in Technique[技术] by (71.8m points)

iphone - 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.

Any help would be appreciated, handling this, thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...