MediaPlayer.start() - Start Playing an Audio File on a MediaPlayer

How to Start Playing an Audio File on a MediaPlayer

MediaPlayer.start() was added in API Level 1
Starts or resumes playback. If playback had previously been paused, playback will continue from where it was paused. If playback had been stopped, or never started before, playback will start at the beginning.

1. Create a MediaPlayer for an Audio Resource

2. In the MainActivity.java file, add the code below to the onCreate method.

if (myMediaPlayer != null) {
try {
myMediaPlayer.start();
} catch (IllegalStateException e) {
//Toast.makeText(this, "IllegalstateException - myMediaPlayer.start", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}

3. Don't forget to Release the MediaPlayer at least on your Activity onStop.

4. Compile and run!

Resources:
http://developer.android.com/reference/android/media/MediaPlayer.html#start()