java - Muting Media Player at certain points in the Game -


hello: want able leave option of muting in below code; sound plays every time gets correct , when 1 gets wrong.

how can mute ? voice on when phone voice muted. in advance.

if (enteredanswer == answer) {                    mediaplayer mediaplayer =  mediaplayer.create(this, r.raw.correct);      mediaplayer.start(); } 

you can use setvolume(float, float):

sets volume on player. api recommended balancing output of audio streams within application. unless writing application control user settings, api should used in preference setstreamvolume(int, int, int) sets volume of streams of particular type. note passed volume values raw scalars in range 0.0 1.0. ui controls should scaled logarithmically.

to mute mediaplayer need pass 0:

mediaplayer.setvolume(0, 0); 

to restore full volume need pass 1:

mediaplayer.setvolume(1, 1); 

Comments