如何设置默认音量?

时间:2014-08-25 09:23:36

标签: android checkbox volume

我的复选框必须将musicbackroud静音。如何更改回默认音量?

        if (checkBox.isChecked()) {
            musicbackground.setVolume(0, 0);}
            else
            {
                ???
            }

1 个答案:

答案 0 :(得分:0)

As far as I can tell MediaPlayer的初始量为1.0

因此,您可以使用一些额外的变量跟踪当前和之前的音量:

float currentVolume = 1.0f;
float previousVolume = 1.0f;

...

// Changing volume to 0
previousVolume = currentVolume;
currentVolume = 0;
musicbackground.setVolume(currentVolume, currentVolume);

...

// Restoring the old volume
temp = previousVolume;
previousVolume = currentVolume;
currentVolume = temp;
musicbackground.setVolume(currentVolume, currentVolume);