Solution 1 :
I’ve got the answer.
I have taken my time to understand that setting the sound in a button under onClickListener by calling mp.start only do not keep the user settings. I also discovered that clicking the button repeatedly secretly raises the audiomanager volume without user consent.
So to have the button click sound play under user set system volume i decided to place a constant setting switching affects which helps to keep to users constant settings.
Now if the user turn down the system volume or switch to silent mode the button click sound will not make a sound.
Below is most correct way of implementing button-click sound code
public void onBtnClick()
{
Log.v(TAG, "Initializing sounds...");
final MediaPlayer mp = MediaPlayer.create(this, R.raw.sound_btn);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.playSoundEffect(SoundEffectConstants.CLICK);
mBrandNewDesc2.setVisibility((mBrandNewDesc2.getVisibility() == View.VISIBLE)
? View.GONE : View.VISIBLE);
Log.v(TAG, "Playing sound...");
mp.start();
}
});
Problem :
I’m wondering if there is something I should do to have my button click controlled by Android MediaPlayer
.
I discovered that even when the phone is set to vibration or silent mode, and the button is clicked it’s still make uncontrolled sound.
public void onBtnClick()
{
Log.v(TAG, "Initializing sounds...");
final MediaPlayer mp = MediaPlayer.create(this, R.raw.sound_btn3);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mBrandNewDesc2.setVisibility((mBrandNewDesc2.getVisibility() == View.VISIBLE)
? View.GONE : View.VISIBLE);
Log.v(TAG, "Playing sound...");
mp.start();
}
});
This is what i did that didn’t work
Settings.System.putInt(getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, 1);
v.playSoundEffect(SoundEffectConstants.CLICK);
Comments
Comment posted by Joseph
Please this mediaPlayer does not have contol with respect to OS mediaplayer control
Comment posted by Joseph
I mean how to integrate this mediaplayer above with android manager so as to have the volume controlled by systemservice