Android.Media.MediaPlayer Class
MediaPlayer class can be used to control playback of audio/video files and streams.

See Also: MediaPlayer Members

Syntax

[Android.Runtime.Register("android/media/MediaPlayer", DoNotGenerateAcw=true)]
public class MediaPlayer : Java.Lang.Object

Remarks

MediaPlayer class can be used to control playback of audio/video files and streams. An example on how to use the methods in this class can be found in Android.Widget.VideoView.

Topics covered here are:

Developer Guides

For more information about how to use MediaPlayer, read the Media Playback developer guide.

State Diagram

Playback control of audio/video files and streams is managed as a state machine. The following diagram shows the life cycle and the states of a MediaPlayer object driven by the supported playback control operations. The ovals represent the states a MediaPlayer object may reside in. The arcs represent the playback control operations that drive the object state transition. There are two types of arcs. The arcs with a single arrow head represent synchronous method calls, while those with a double arrow head represent asynchronous method calls.

From this state diagram, one can see that a MediaPlayer object has the following states:

Applications may want to register for informational and error events in order to be informed of some internal state update and possible runtime errors during playback or streaming. Registration for these events is done by properly setting the appropriate listeners (via calls to MediaPlayer.SetOnPreparedListener(.IOnPreparedListener)setOnPreparedListener, MediaPlayer.SetOnVideoSizeChangedListener(.IOnVideoSizeChangedListener)setOnVideoSizeChangedListener, MediaPlayer.SetOnSeekCompleteListener(.IOnSeekCompleteListener)setOnSeekCompleteListener, MediaPlayer.SetOnCompletionListener(.IOnCompletionListener)setOnCompletionListener, MediaPlayer.SetOnBufferingUpdateListener(.IOnBufferingUpdateListener)setOnBufferingUpdateListener, MediaPlayer.SetOnInfoListener(.IOnInfoListener)setOnInfoListener, MediaPlayer.SetOnErrorListener(.IOnErrorListener)setOnErrorListener, etc). In order to receive the respective callback associated with these listeners, applications are required to create MediaPlayer objects on a thread with its own Looper running (main UI thread by default has a Looper running).

[Android Documentation]

Requirements

Namespace: Android.Media
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1