Reputation: 495
For the record, I am not asking how to play a sound programmatically with the MediaPlayer. I know how to do that quite well.
I first searched how to replace the default click sound of a Button in the XML. But I have not found out if that is possible. Most answers suggest to use the MediaPlayer to play a sound effect somewhere in/from the onClick() event of the Button, so I assume that's the best way to go?
If I use the MediaPlayer to play a sound when a Button is clicked, do I have to disable the default click sound as well, or will both play, or will Android just know to ignore the default click sound? Should I call setSoundEffectsEnabled(false) on the Button before I play my own sound?
It seems very strange to me that I can't just replace the default click sound of a Button (is it possible to do that?)
Upvotes: 2
Views: 561
Reputation: 3544
you may wish to check this link as well: Playing sound effect (CLICK/NAVIGATION_RIGHT) for button clicks - Android
seems that sound effects are kept as android.view.SoundEffectConstants.<value>
correspondingly, there might be a way of adding your own custom sound
it is all about passing the value of sound effect you'd like to hear, into <view variable>.playSoundEffect(<sound effect value>);
so you may try to add your sound into res
and call that method with its R value
Upvotes: 0
Reputation: 126485
Just set android:soundEffectsEnabled=false
in your theme defined into your res/styles.xml
or programatically:
myButton.setSoundEffectsEnabled(false);
Upvotes: 0