Declare and Initialize a MediaPlayer

How to Declare and Initialize a Media Player

MediaPlayer was added in API Level 1

1. If you don't already have an Android app, create one.

2. In the MainActivity.java file, add the below code to the imports section.

import android.media.MediaPlayer; 

3. In the MainActivity.java file, add the below code to the onCreate method. This will create a MediaPlayer object named myMediaPlayer and initialized it to null.

MediaPlayer myMediaPlayer = null; 

4. Compile and run!

Related Articles:

Resources:
http://developer.android.com/reference/android/media/MediaPlayer.html
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html