iPhone:如何在独立于音量设置的情况下大声播放本地通知声音? [英] iPhone: How to play local notification sound loud independent of volume setting?

查看:25
本文介绍了iPhone:如何在独立于音量设置的情况下大声播放本地通知声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FoneHome iPhone 应用程序具有一项功能,您可以在其中播放声音作为本地通知的一部分.无论 iPhone 的音量设置为多少,声音都很大.

The FoneHome iPhone app has a feature where you can play a sound as part of a local notification. That sound is loud regardless of what the iPhone's volume level is set at.

如何获得本地通知(或推送)以播放与当前 iPhone 音量无关的大声音频警报?我尝试将 soundName 设置为 WAV 文件,但它会以任何当前音量播放,而且我看不到其他设置选项.

How is it possible to get a local notification (or push) to play an audio alert that is loud independent of what the current iPhone volume level is? I tried just setting the soundName to a WAV file but it plays at whatever the current volume is, and I see no options to set it otherwise.

推荐答案

尝试使用以下代码

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.但这样做可能会使声音有点失真.

Here 'x' is a floating point value which normally ranges from 0.0 to 1.0. However to increase the Volume level assign x value >10.0. But doing this may distort the sound a bit.

这篇关于iPhone:如何在独立于音量设置的情况下大声播放本地通知声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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