首页 文章

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

提问于
浏览
8

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

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

1 回答

  • 2

    尝试使用以下代码

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

相关问题