iPhone: How to play local notification sound loud independent of volume setting?

后端 未结 1 1261
北海茫月
北海茫月 2021-01-02 10:16

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.

相关标签:
1条回答
  • 2021-01-02 11:07

    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];
    

    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.

    0 讨论(0)
提交回复
热议问题