Load mp3 file with MediaPlayer and play
package app.test;
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
public class Test extends Activity implements OnCompletionListener {
MediaPlayer mediaPlayer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onCompletion(MediaPlayer mp) {
mediaPlayer.start();
}
public void onStart() {
super.onStart();
mediaPlayer = MediaPlayer.create(this, R.raw.s);//raw/s.mp3
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.start();
}
public void onStop() {
super.onStop();
// Log.v("CustomAudioPlayer","onStop Called");
mediaPlayer.stop();
mediaPlayer.release();
}
}
Related examples in the same category