I'm using the following code to play a mp3 from raw folder but nothing happens! can anyone help me? thanks
MediaPlayer mp = new MediaPlayer();
mp = MediaPlayer.create(ShapesActivity.this, R.raw.circle);
mp.start();
mp.release();
I'm using the following code to play a mp3 from raw folder but nothing happens! can anyone help me? thanks
MediaPlayer mp = new MediaPlayer();
mp = MediaPlayer.create(ShapesActivity.this, R.raw.circle);
mp.start();
mp.release();
You are releasing the mediaplayer right after you start it, so the sound doesn't play. You need to remove mp.release()
As pointed out @TuomasK you release the media before playing it. You should implement OnCompletionListener
to release MediaPlayer properly.
You can do it like this:
MediaPlayer mMp = MediaPlayer.create(ShapesActivity.this, R.raw.circle);
mMp.start();
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.reset();
mp.release();
};
});