How to increase volume of mediaPlayer

☆樱花仙子☆ 提交于 2019-12-07 16:42:35

问题


I am writing an app that in some situations warns user with an alarm sound. My problem is that in some situation volume of media playing may be decreased by user or even media volume is silent. I want to check the volume programatically and increase it to 100% and then play alarm.

Any idea? Note that I have tested mediaPlayer.setVolume(1,1) and nothing changed.


回答1:


This isn't the function for setting the volume. Here it's the setting of the volume to any value:

AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
// For example to set the volume of played media to maximum.
audioManager.setStreamVolume (AudioManager.STREAM_MUSIC, audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC),0);


来源:https://stackoverflow.com/questions/10427713/how-to-increase-volume-of-mediaplayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!