i have a little problem with the media player class. I have a button, and by pressing it a sound will be played. The thing is that there is some delay between when i press the button and when the sound is played, and if i press it too many times the media player dies, and then no sound is played at all and i get the following errors:
ERROR/MediaPlayer(3960): error (-19, 0)
ERROR/AudioTrack(3931): AudioFlinger could not create track, status: -12
ERROR/AudioSink(3931): Unable to create audio track
Here’s the code:
Button b = (Button)findViewById(R.id.button);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AssetFileDescriptor afd;
try {
afd = getAssets().openFd("bassdrum6.mp3");
player = new MediaPlayer();
player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
player.prepare();
player.start();
} catch (IOException e) {
e.printStackTrace();
}
}
});
I don’t know what’s wrong here. I need some help.
Thanks in advance.
Your going to want to use an on touch listener if you want it to play while the button is being pressed