如何控制自己的Android应用的声音量
我想这个问题的答案一定是典型的。关键是,当您单击它们时,我有一些播放声音的按钮。我想控制声音卷。我如何控制声音卷?我正在使用以下代码:
private fun playSound() {
val sound = getSystemService(Context.AUDIO_SERVICE) as AudioManager
sound.playSoundEffect(AudioManager.FX_KEY_CLICK, 1f)
}
I imagine the answer to this question must be something quite typical. The point is that I have some buttons that play sounds when you click on them. I want to control the sound volume. How do I control the sound volume? I am using the following code:
private fun playSound() {
val sound = getSystemService(Context.AUDIO_SERVICE) as AudioManager
sound.playSoundEffect(AudioManager.FX_KEY_CLICK, 1f)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
/参考/Android/Media/AudioManager#PlaySoundFect(INT,%20Float
)因此,您需要调整第二个参数。我没有使用过它,但是说那是标量,所以我想
1
是完整的卷吗?它没有提到任何其他值是最大常数或任何其他值。-1
如果很方便的话,您的声音比当前的媒体音量设置更安静。您需要在0到1之间使用不同的值(我想!),看看您需要什么https://developer.android.com/reference/android/media/AudioManager#playSoundEffect(int,%20float
)So you need to adjust that second parameter. I haven't used it, but it says that's a scalar so I'd imagine
1
is full volume? It doesn't mention any other value as a max constant or anything.-1
gives you a sound a little quieter than the current media volume setting, if that's convenient. You'll need to play around with different values between 0 and 1 (I assume!) and see what you need