iPhone:如何独立于音量设置来大声播放本地通知声音?

标签 iphone audio notifications local volume

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/

相关文章:

iphone - 在 UIWebView 中使用进度条?

iphone - 将名称和电子邮件存储在数组列表中时,创建具有电子邮件和名称属性的对象播放器是可行的方法吗?

ios - 如何检测 iOS 应用程序正在越狱手机上运行?

python - Freeze.py上的Tensorflow简单音频识别错误

Android 'Couldn' t expand remoteViews for ...' 以编程方式创建布局时

Android - 构建通知,TaskStackBuilder.addParentStack 不起作用

iphone - xcode - 使搜索栏出现/消失

javascript - webRTC 视频聊天中的噪音/回声

javascript - 如果<audio>源在Javascript中更改,如何将cookie的值设置为0

javascript - 设置通知系统的最佳方法?