Set device volume on iPhone

你离开我真会死。 提交于 2019-12-09 06:43:02

问题


I'm writing an app that uses AVAudioPlayers to play sounds and I need the sounds to play at absolute MAX volume. Yes you can set the relative volume for an AVAudioPlayer, but if the user has the device volume turned down, the sound will still play quietly.

I know that Apple says that the device volume cannot be overridden, but yet the Alarm Clock apps out there somehow are able to do this - so there must be a way.

I believe that this can be done using Audio Queues using the call:

AudioQueueSetParameter(aq, kAudioQueueParam_Volume, 1.0);

But my code needs to use the AVAudioPlayer to play the sounds so I don't think this approach will be of any help.

There is also a way to use an undocumented function of MPVolumeView to accomplish this, but apparently someone already had an app rejected for using this method.

Any other ideas?


回答1:


The comment from the anonymous for this site:

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

does actually work.




回答2:


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'm not entirely sure if it will work, but I believe it should. It seems you might have to modify the height and width



来源:https://stackoverflow.com/questions/2393124/set-device-volume-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!