Android : How to set MediaPlayer volume programmatically?
如何以编程方式设置媒体播放器音量。我将它用于警报通知。任何帮助都非常感谢,并提前感谢。
使用 AudioManager,您可以简单地控制媒体播放器的音量。
1 2 | AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0); |
也来自 MediaPlayer(但我没有尝试过)
1 | setVolume(float leftVolume, float rightVolume) |
Since: API Level 1
Sets the volume on this player. This API is recommended for balancing
the output of audio streams within an application. Unless you are
writing an application to control user settings, this API should be
used in preference to setStreamVolume(int, int, int) which sets the
volume of ALL streams of a particular type. Note that the passed
volume values are raw scalars. UI controls should be scaled
logarithmically.
Parameters
leftVolume left volume scalar
rightVolume right volume scalar
本文来自网络,不代表菜鸟教程之家立场,转载请注明出处。
使用AudioManager的setStreamVolume方法可以控制Android设备的媒体播放器音量。例如,可以通过调用`audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,20,0);`来设置音乐流的音量。此外,MediaPlayer类自身的setVolume方法也可用于设置左右声道的音量。注意,这些值应根据需要进行对数缩放,因为UI控件通常会使用对数尺度显示音量。
4334

被折叠的 条评论
为什么被折叠?



