In my application, I need to play sound from volume 0 to the maximum volume of the system (this is an alarm application).
I am currently using AVAudioPlayer for audio playback and MPMusicPlayerController to maximize device volume throughout the alarm
MPMusicPlayerController.applicationMusicPlayer.volume = 1.0; NSString *fileName = [NSString stringWithFormat:alarm.sound]; fileName = [fileName stringByDeletingPathExtension]; NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"aifc"]; NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath]; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil]; audioPlayer.volume = 0.0; audioPlayer.numberOfLoops = -1; [audioPlayer prepareToPlay]; audioPlayer.play;
and then I plan a timer to increase the volume
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(pollTimeForGradualVolumeIncrease) userInfo:nil repeats:YES];
// Turn up the volume gradually
- (void)pollTimeForGradualVolumeIncrease { timerSecond += 1; if (audioPlayer.volume < 1.0 && timerSecond % 1 == 0) { [audioPlayer setVolume:audioPlayer.volume + 0.02]; UISlider *slider = volumeSliderView.subviews[0]; [slider setValue:1.0 animated:NO]; } else if (audioPlayer.volume >= 1.0) { timerSecond = 0; timer.invalidate; timer = nil; } }
The problem is that the iOS level indicator will appear when installing MPMusicPlayerController.applicationMusicPlayer.volume
Is there a way to play the sound file at the maximum level of the device without displaying the iOS volume change indicator?
max ios iphone audio volume
gabe.roze
source share