在iPhone上设置设备音量 [英] Set device volume on iPhone
问题描述
我正在编写一个使用 AVAudioPlayers
来播放声音的应用,我需要以绝对MAX音量播放声音。是的,您可以设置 AVAudioPlayer
的相对音量,但如果用户关闭了设备音量,声音仍会静音播放。
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.
我知道Apple说设备音量无法被覆盖,但闹钟应用程序在某种程度上可以做到这一点 - 所以必须有办法。
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);
但是我的代码需要使用 AVAudioPlayer
播放声音,所以我不认为这种方法会有任何帮助。
But my code needs to use the AVAudioPlayer
to play the sounds so I don't think this approach will be of any help.
还有一种方法可以使用的无证件功能MPVolumeView
来实现这一目标,但显然有人因使用此方法而拒绝了应用程序。
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.
还有其他想法吗?
推荐答案
float volume;
[[MPMusicPlayerController applicationMusicPlayer] setVolume:volume];
确实有效。
这篇关于在iPhone上设置设备音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!