Android provides a standard means to play audio or video: the
MediaPlayer class. For audio content, you can also play back raw data,
which is useful in sophisticated applications where you generate the
MediaPlayer goes through several states
during its life cycle:
MediaPlayer is instantiated.
The media source is set.
MediaPlayer is preparing the media
source for playback.
MediaPlayer is prepared for
Playback is in progress.
Playback has been paused.
Playback of source is done (the playback can be started again).
MediaPlayer is no longer prepared to
play the source.
MediaPlayer is no more, and all
associated resources are released.
For details on these states, view the state
diagram provided on the Developers site at http://developer.android.com/reference/android/media/MediaPlayer.html#StateDiagram.
To get started with
it’s useful at this point to view it as a series of
steps in your application:
MediaPlayer instance through the
create() method (idle state).
MediaPlayer with the media source to
play (initialized state).
MediaPlayer for playback through the
prepare() method (preparing and prepared
MediaPlayer through the
start() method (started state).
During playback, if desired, you can
pause, stop, or replay the
MediaPlayer (started, paused, playback
complete, and stopped states).