我有这样的代码:
-(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上的标准物理音量按钮来控制音量。
如果我把这个音量降到1,它就会播放,很好,但是如果我把设备音量调到最大,它也是一样的音量。
任何帮助都将不胜感激,处理这件事,谢谢。
发布于 2012-11-08 06:01:31
在这个话题上,我也遇到了类似的问题。
我的问题是,有一个我没有意识到的全球环境。
在设置应用程序中,位于
常规>声音>振铃器和警报
如果'Change with Button‘设置为Off
,则使用AudioServicesPlaySystemSound()
的声音将始终以最大音量播放(但其他声音API,如AVAudioPlayer
将考虑设备的音量)。
https://stackoverflow.com/questions/10855874
复制相似问题