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

查看:261
本文介绍了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.

推荐答案

尝试使用以下code

Try using the following code

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天全站免登陆