AudioServicesPlaySystemSound Volume?

橙三吉。 提交于 2019-11-27 01:25:21

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/10855874/audioservicesplaysystemsound-volume

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!