Set device volume on iPhone

I am writing an application that uses AVAudioPlayers to play sounds, and I need sounds to play on an absolute MAX volume. Yes, you can set the relative volume for AVAudioPlayer , but if the user has the volume of the device, the sound will still play quietly.

I know that Apple says that the volume of the device cannot be overridden, but still Alarm Clock applications can somehow do it there - so there should be a way.

I believe this can be done using sound queues with a call:

 AudioQueueSetParameter(aq, kAudioQueueParam_Volume, 1.0); 

But my code should use AVAudioPlayer to play sounds, so I don't think this approach would be useful.

There is also a way to use the undocumented MPVolumeView function for this, but apparently someone has already had the application rejected to use this method.

Any other ideas?

+4
source share
2 answers

Comment anonymous for this site :

 float volume; [[MPMusicPlayerController applicationMusicPlayer] setVolume:volume]; 

really works.

+6
source

I came across this:

  MPVolumeView *volumeView1 = [[MPVolumeView alloc] initWithFrame:CGRectMake(4, 316, sk.size.width, sk.size.height)]; [volumeView1 sizeToFit]; [self.view addSubview:volumeView1]; [volumeView1 release]; 

I am not entirely sure that this will work, but I believe that this should happen. It seems you might have to change the height and width

0
source

Source: https://habr.com/ru/post/1303346/


All Articles