How to play a sound file with maximum volume in iOS without changing the sound indicator

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?

+8
max ios iphone audio volume
source share
1 answer

I experimented with related things 8 months ago, and as far as I remember, if MPVolumeView is present, iOS does not show an indicator of system volume change.

If you really don't want to see MPVolumeView, I suppose you could hide it behind another view.

+3
source share

All Articles