vendredi 1 septembre 2017

Sound is muted / unmuted too late

I set up a Checkbox, If it is unchecked the mediaplayers should immediately be unmuted, when checked immediately muted, now I have the problem that when I check / uncheck the checkbox the sound will be muted/unmuted as recently as the users restarts the app or switch to another activity (menu2) and then back to the main activity. How can I do that the mediaplayers will be muted immediately?

Piece of code from the mute/unmute section:

         checkBoxmp.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            editor.putBoolean("playSounds", !isChecked);
            editor.commit();
            if (null != mp && null != mp2) {
                if (!isChecked) {
                    mp.setVolume(1, 1);
                    mp2.setVolume(1, 1);
                } else {
                    mp.setVolume(0, 0);
                    mp2.setVolume(0, 0);
                }
            }
        }
    });

    final boolean playSounds = mypref.getBoolean("playSounds", false);
    checkBoxmp.setChecked(!playSounds);




Aucun commentaire:

Enregistrer un commentaire