音频服务播放系统音量? [英] AudioServicesPlaySystemSound Volume?

查看:27
本文介绍了音频服务播放系统音量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

-(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);
}

我这样称呼它:

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

这很好用,但是我无法控制音量.我只是想让用户使用 iPad 上的标准物理音量按钮来控制音量.

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.

如果我将此音量调低为 1,它会播放,很棒,但是如果我将设备音量调高到最大相同音量.

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.

推荐答案

在这个话题上我也遇到了类似的问题.

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.

在设置应用程序中,在

General > Sounds > Ringer and Alerts

General > Sounds > Ringer and Alerts

如果 'Change with Buttons' 设置为 Off,则使用 AudioServicesPlaySystemSound() 的声音将始终以最大音量播放(但其他声音 API,例如 AVAudioPlayer 将尊重设备的音量).

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

这篇关于音频服务播放系统音量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆