Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to produce default sound

Tags:

android

I hava a set of buttons. When I click on a button it should produce sound.

Example:

Button b=new Button(this);
b.setText("Press");
b.setOnClickListener(new OnClickListener)[
public void click(View v)
{
   b.setSoundEffectsEnabled(true);
});}

This doesn't work though, can anyone help me please.

like image 499
AndroidDev Avatar asked Jan 19 '26 20:01

AndroidDev


1 Answers

What do you mean on default sound? If you want to play your own sound, you must create a MediaPlayer like this.

MediaPlayer mediaPlayer = MediaPlayer.create(this, [here is your sound in the raw file]);

and in the click method you need to implement this:

mediaPlayer.start();

or you can use soundpool too.

Hope it helps.

like image 60
Zwiebel Avatar answered Jan 21 '26 13:01

Zwiebel