简体   繁体   English

iOS播放音量恒定的声音文件,与用户设置无关

[英]iOS play sound file with constant volume, independent of user settings

Is there any way in iOS to keep playing a sound file at a constant sound volume? iOS中有什么方法可以保持恒定音量播放声音文件? So no matter if the user did set the ringtone of his phone to very low volume, I still want to play my audio file at the same volume as if the phone was set to loud. 因此,无论用户是否将手机的铃声设置为非常低的音量,我仍然希望以与将手机设置为大音量相同的音量播放音频文件。 Kind of like what Siri does. 有点像Siri所做的。 She's also independent of every other sound-volume setting. 她还独立于其他所有音量设置。

Thanks 谢谢

For everybody wondering. 对于每个人都想知道的。 AVAudioPlayer has a property volume that can be set higher than 1. So you would figure out what the current device volume is using AVAudioSession.sharedInstance().outputVolume and then adjust the AVAudioPlayer volume to compensate the difference. AVAudioPlayer的属性volume可以设置为大于1。因此,您可以使用AVAudioSession.sharedInstance().outputVolume找出当前设备的音量,然后调整AVAudioPlayer的音量以补偿差异。

Note that the sound quality is not going to improve ;) So best thing is just to not do that ;) 请注意,声音质量不会提高;)所以最好的办法就是不要这样做;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM