【问题标题】:iPhone: How to play local notification sound loud independent of volume setting?iPhone:如何独立于音量设置大声播放本地通知声音?
【发布时间】:2011-02-24 20:52:42
【问题描述】:

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

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

【问题讨论】:

  • FoneHome 在后台连续运行,并使用推送通知以外的其他方式播放声音。
  • 你可以在你的应用程序中做任何你想做的事情,但是这样会违反用户对自己设备的控制。如果我调低音量,我希望它保持这种状态。

标签: iphone audio notifications local volume


【解决方案1】:

试试下面的代码

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-25
    相关资源
    最近更新 更多