我的复选框必须将musicbackroud静音。如何更改回默认音量?
if (checkBox.isChecked()) {
musicbackground.setVolume(0, 0);}
else
{
???
}
答案 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);