Android : How to set MediaPlayer volume programmatically?

后端 未结 10 532
你的背包
你的背包 2020-12-08 04:17

How to set the mediaplayer volume programmatically. I use it for alarm notification. Any help is highly appreciated and thanks in advance.

10条回答
  •  无人及你
    2020-12-08 04:42

    Try This

    protected static void setVolume(int volume) {
            currentVolume = volume;
            {
                if (volume == 1) {
                    volume = 2;
                }
                try {
                    float vol = ((float) volume / CONSTANT.SYSTEM_MAX_VOLUME);
                    mediaPlayer.setVolume(vol, vol);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
    
        }
    

提交回复
热议问题