MediaPlayer Class

Definition

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

[Android.Runtime.Register("android/media/MediaPlayer", ApiSince=1, DoNotGenerateAcw=true)]
public class MediaPlayer : Java.Lang.Object, Android.Media.IVolumeAutomation, IDisposable
type MediaPlayer = class
    inherit Object
    interface IVolumeAutomation
    interface IJavaObject
    interface IDisposable
Inheritance
MediaPlayer
Attributes
Implements

Remarks

Android platform documentation

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

MediaPlayer()

Default constructor.

MediaPlayer(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Fields

MediaErrorIo
MediaErrorMalformed
MediaErrorTimedOut
MediaErrorUnsupported
MediaMimetypeTextSubrip

MIME type for SubRip (SRT) container.

VideoScalingModeScaleToFit
Obsolete.

Specifies a video scaling mode.

VideoScalingModeScaleToFitWithCropping
Obsolete.

Specifies a video scaling mode.

Properties

AudioSessionId

Returns the audio session ID.

Class

Returns the unique instance of Class that represents this object's class.

(Inherited from Object)
CurrentPosition

Gets the current playback position.

Duration

Gets the duration of the file.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsPlaying

Checks whether the MediaPlayer is playing.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
Looping

Checks whether the MediaPlayer is looping or non-looping.

Metrics
PeerReference (Inherited from Object)
PlaybackParams
SyncParams
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Timestamp
VideoHeight

Returns the height of the video.

VideoWidth

Returns the width of the video.

Methods

AddTimedTextSource(Context, Uri, String)

Adds an external timed text source file (Uri).

AddTimedTextSource(FileDescriptor, Int64, Int64, String)

Adds an external timed text file (FileDescriptor).

AddTimedTextSource(FileDescriptor, String)

Adds an external timed text source file (FileDescriptor).

AddTimedTextSource(String, String)

Adds an external timed text source file.

AttachAuxEffect(Int32)

Attaches an auxiliary effect to the player.

Clone()

Creates and returns a copy of this Object.

(Inherited from Object)
Create(Context, Int32)

Convenience method to create a MediaPlayer for a given resource id.

Create(Context, Int32, AudioAttributes, Int32)

Same factory method as Create(Context, Int32) but that lets you specify the audio attributes and session ID to be used by the new MediaPlayer instance.

Create(Context, Uri)

Convenience method to create a MediaPlayer for a given Uri.

Create(Context, Uri, ISurfaceHolder)

Convenience method to create a MediaPlayer for a given Uri.

Create(Context, Uri, ISurfaceHolder, AudioAttributes, Int32)
CreateVolumeShaper(VolumeShaper+Configuration)
DeselectTrack(Int32)

Deselect a track.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Compares this instance with the specified object and indicates if they are equal.

(Inherited from Object)
GetDrmInfo()
GetDrmPropertyString(String)
GetHashCode()

Returns an integer hash code for this object.

(Inherited from Object)
GetKeyRequest(Byte[], Byte[], String, MediaDrmKeyType, IDictionary<String,String>)
GetSelectedTrack(MediaTrackType)

Returns the index of the audio, video, or subtitle track currently selected for playback, The return value is an index into the array returned by GetTrackInfo(), and can be used in calls to SelectTrack(Int32) or DeselectTrack(Int32).

GetTrackInfo()

Returns an array of track information.

JavaFinalize()

Invoked when the garbage collector has detected that this instance is no longer reachable.

(Inherited from Object)
Notify()

Causes a thread which is waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up.

(Inherited from Object)
NotifyAll()

Causes all threads which are waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up.

(Inherited from Object)
Pause()

Pauses playback.

Prepare()

Prepares the player for playback, synchronously.

PrepareAsync()

Prepares the player for playback, asynchronously.

PrepareDrm(UUID)
ProvideKeyResponse(Byte[], Byte[])
Release()

Releases resources associated with this MediaPlayer object.

ReleaseDrm()
Reset()

Resets the MediaPlayer to its uninitialized state.

RestoreKeys(Byte[])
SeekTo(Int32)

Seeks to specified time position.

SeekTo(Int64, MediaPlayerSeekMode)
SelectTrack(Int32)

Selects a track.

SetAudioAttributes(AudioAttributes)

Sets the audio attributes for this MediaPlayer.

SetAudioStreamType(Stream)
Obsolete.

Sets the audio stream type for this MediaPlayer.

SetAuxEffectSendLevel(Single)

Sets the send level of the player to the attached auxiliary effect.

SetDataSource(AssetFileDescriptor)
SetDataSource(Context, Uri)

Sets the data source as a content Uri.

SetDataSource(Context, Uri, IDictionary<String,String>)
SetDataSource(Context, Uri, IDictionary<String,String>, IList<HttpCookie>)
SetDataSource(FileDescriptor)

Sets the data source (FileDescriptor) to use.

SetDataSource(FileDescriptor, Int64, Int64)

Sets the data source (FileDescriptor) to use.

SetDataSource(MediaDataSource)
SetDataSource(String)

Sets the data source (file-path or http/rtsp URL) to use.

SetDataSourceAsync(AssetFileDescriptor)
SetDataSourceAsync(Context, Uri)
SetDataSourceAsync(Context, Uri, IDictionary<String,String>)
SetDataSourceAsync(Context, Uri, IDictionary<String,String>, IList<HttpCookie>)
SetDataSourceAsync(FileDescriptor)
SetDataSourceAsync(FileDescriptor, Int64, Int64)
SetDataSourceAsync(MediaDataSource)
SetDataSourceAsync(String)
SetDisplay(ISurfaceHolder)

Sets the ISurfaceHolder to use for displaying the video portion of the media.

SetDrmPropertyString(String, String)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetNextMediaPlayer(MediaPlayer)

Set the MediaPlayer to start when this MediaPlayer finishes playback (i.e. reaches the end of the stream).

SetOnBufferingUpdateListener(MediaPlayer+IOnBufferingUpdateListener)

Register a callback to be invoked when the status of a network stream's buffer has changed.

SetOnCompletionListener(MediaPlayer+IOnCompletionListener)

Register a callback to be invoked when the end of a media source has been reached during playback.

SetOnDrmConfigHelper(MediaPlayer+IOnDrmConfigHelper)
SetOnDrmInfoListener(MediaPlayer+IOnDrmInfoListener)
SetOnDrmInfoListener(MediaPlayer+IOnDrmInfoListener, Handler)
SetOnDrmPreparedListener(MediaPlayer+IOnDrmPreparedListener)
SetOnDrmPreparedListener(MediaPlayer+IOnDrmPreparedListener, Handler)
SetOnErrorListener(MediaPlayer+IOnErrorListener)

Register a callback to be invoked when an error has happened during an asynchronous operation.

SetOnInfoListener(MediaPlayer+IOnInfoListener)

Register a callback to be invoked when an info/warning is available.

SetOnPreparedListener(MediaPlayer+IOnPreparedListener)

Register a callback to be invoked when the media source is ready for playback.

SetOnSeekCompleteListener(MediaPlayer+IOnSeekCompleteListener)

Register a callback to be invoked when a seek operation has been completed.

SetOnTimedMetaDataAvailableListener(MediaPlayer+IOnTimedMetaDataAvailableListener)
SetOnTimedTextListener(MediaPlayer+IOnTimedTextListener)

Register a callback to be invoked when a timed text is available for display.

SetOnVideoSizeChangedListener(MediaPlayer+IOnVideoSizeChangedListener)

Register a callback to be invoked when the video size is known or updated.

SetScreenOnWhilePlaying(Boolean)

Control whether we should use the attached SurfaceHolder to keep the screen on while video playback is occurring.

SetSurface(Surface)

Sets the Surface to be used as the sink for the video portion of the media.

SetVideoScalingMode(VideoScalingMode)

Sets video scaling mode.

SetVolume(Single, Single)

Sets the volume on this player.

SetWakeMode(Context, WakeLockFlags)

Set the low-level power management behavior for this MediaPlayer.

Start()

Starts or resumes playback.

Stop()

Stops playback after playback has been stopped or paused.

ToArray<T>() (Inherited from Object)
ToString()

Returns a string containing a concise, human-readable description of this object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.

(Inherited from Object)
Wait(Int64)

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

(Inherited from Object)
Wait(Int64, Int32)

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

(Inherited from Object)

Events

BufferingUpdate
Completion
DrmInfoEvent
DrmPrepared
Error
Info
Prepared
SeekComplete
TimedMetaDataAvailable
TimedText
VideoSizeChanged

Explicit Interface Implementations

IJavaObjectEx.IsProxy (Inherited from Object)
IJavaObjectEx.KeyHandle (Inherited from Object)
IJavaObjectEx.NeedsActivation (Inherited from Object)
IJavaObjectEx.ToLocalJniHandle() (Inherited from Object)
IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to