Reputation: 127
I tried to build a button that on click plays a sound.
Below is my code. When I click the button I get Error (-19, 0).
What does it mean?
public void onClick(View v) {
MediaPlayer click = MediaPlayer.create(Timer.this, R.raw.click);
click.start();
}
});
Upvotes: 0
Views: 98
Reputation: 386
well to do that...its better to make a new folder called raw inside the resource folder and copy the sound clip there. then add the following under onClick if u wanna play sound on click of a button:
public void onClick(View v) {
ourSong = MediaPlayer.create(Incoming.this, R.raw.abcd);
ourSong.start(); //where abcd is ur sound file and Incoming is ur java class
where u need to define MediaPlayer ourSong; like this:
public class Incoming extends Activity{
MediaPlayer ourSong;
Upvotes: 1
Reputation: 86
It's better to use Soundpool for little sounds like a click. Watch this video: http://thenewboston.org/watch.php?cat=6&number=79
Upvotes: 1
Reputation: 21182
Playing sounds with MediaPlayer
isn't a good idea. you should consider using the SoundPool
take a look at the SoundPool's documentation
Upvotes: 1