且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使声音池静音?

更新时间:2021-07-28 20:57:58

向您的MediaPlayerPool类添加变量,我们将其称为mute

Add a variable to your MediaPlayerPool class, let's call it mute

public boolean mute = false;

具有一个静音/取消静音按钮,并在其onClick方法上(将切换):

Have a mute/unmute button and on its onClick method (will toggle):

MediaPlayerPool.getInstance().mute = !MediaPlayerPool.getInstance().mute

,您的playSound方法变为

public void playSound(int soundId) {
    if(!mute) {
        // stick your current code here
    }
}