FoneHome iPhone 应用程序有一项功能,您可以播放声音作为本地通知的一部分。无论 iPhone 的音量设置为多少,声音都很响亮。
如何获得本地通知(或推送)以播放响亮的音频警报,而与当前 iPhone 的音量级别无关?我尝试将 soundName 设置为 WAV 文件,但它会以当前音量播放,而且我没有看到其他设置选项。
最佳答案
尝试使用以下代码
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audiofile.mp3", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[audioPlayer setVolume:x];
if (audioPlayer == nil)
NSLog([error description]);
else
[audioPlayer play];
这里的“x”是一个浮点值,通常范围从 0.0 到 1.0。但是,要增加音量级别,请指定 x 值 >10.0。但这样做可能会使声音有点失真。
关于iPhone:如何独立于音量设置来大声播放本地通知声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5110323/