如何在 Android 中获取/设置媒体音量(不是铃声音量)?
有没有办法获取/设置媒体音量?我已尝试以下操作:
AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int currentVolume = audio.getStreamVolume(AudioManager.STREAM_RING);
但它返回铃声音量。
Is there a way to get/set media volume? I have tried the following:
AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int currentVolume = audio.getStreamVolume(AudioManager.STREAM_RING);
but it returns the ringtone volume.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
onCreate 内部:
覆盖 onKeyDown:
Inside onCreate:
Override onKeyDown:
您应该使用
AudioManager.STREAM_MUSIC
而不是AudioManager.STREAM_RING
这个问题已经在此处讨论过。
Instead of
AudioManager.STREAM_RING
you shoul useAudioManager.STREAM_MUSIC
This question has already discussed here.
尝试一下:
setVolumeControlStream(AudioManager.STREAM_MUSIC);
Have a try with this:
setVolumeControlStream(AudioManager.STREAM_MUSIC);
您可以将您的活动设置为使用特定的音量。在您的活动中,使用以下其中一项:
You can set your activity to use a specific volume. In your activity, use one of the following:
如果您碰巧想要调整音量条(类似于您在 iPhone 的 iPod 应用程序上看到的内容),请按以下步骤操作。
If you happen to have a volume bar that you want to adjust –similar to what you see on iPhone's iPod app– here's how.
以下代码将媒体流音量设置为最大:
The following code will set the media stream volume to max:
将音量设置为 0
将音量设置为满
可以通过更改 0 到 20 之间的索引值来调整音量
To set volume to 0
To set volume to full
the volume can be adjusted by changing the index value between 0 and 20