I have the following 2 lines of code:
myButton.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
myButton.playSoundEffect(SoundEffectConstants.CLICK);
When I press the button, haptic feedback works fine but no audio is heard.
Anybody had this problem when they started with Android?
I had this problem and it turned out to be something quite stupid on my part. I had disabled "Audible Selection" for the entire phone. On the home page, it's on Settings-->Sound-->Audible selection. There is probably a programmatic way to do the same thing but I have not found it yet.
I also had the same problem. On my Samsung Galaxy S4, the path is Settings --> My Device --> Sound --> Touch Sounds (under the System heading). Once I enabled this, then the default system sounds started working on my app.
Well, I came across the same situation, The trick was, to use Audiomanager.
define an AudioManager in the Activity class.
AudioManager audioManager;
Initialise in onCreate.
audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
In the click method, use the audioManager to play the sound.
public void play(View view) {
audioManager.playSoundEffect(SoundEffectConstants.CLICK,1.0f);
}
Note that the volume is given as 1.0f
if you don't specify the volume, you won't hear any sound.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With