MediaPlayer 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
MediaPlayerMediaPlayer
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() MediaPlayer()

Default constructor.

MediaPlayer(IntPtr, JniHandleOwnership) MediaPlayer(IntPtr, JniHandleOwnership)

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

Fields

MediaErrorIo MediaErrorIo
MediaErrorMalformed MediaErrorMalformed
MediaErrorTimedOut MediaErrorTimedOut
MediaErrorUnsupported MediaErrorUnsupported
MediaMimetypeTextSubrip MediaMimetypeTextSubrip

MIME type for SubRip (SRT) container.

VideoScalingModeScaleToFit VideoScalingModeScaleToFit

Specifies a video scaling mode.

VideoScalingModeScaleToFitWithCropping VideoScalingModeScaleToFitWithCropping

Specifies a video scaling mode.

Properties

AudioSessionId AudioSessionId

Returns the audio session ID.

Class Class

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

(Inherited from Object)
CurrentPosition CurrentPosition

Gets the current playback position.

Duration Duration

Gets the duration of the file.

Handle Handle

The handle to the underlying Android instance.

(Inherited from Object)
IJavaObjectEx.IsProxy IJavaObjectEx.IsProxy Inherited from Object
IJavaObjectEx.KeyHandle IJavaObjectEx.KeyHandle Inherited from Object
IJavaObjectEx.NeedsActivation IJavaObjectEx.NeedsActivation Inherited from Object
IJavaPeerable.JniManagedPeerState IJavaPeerable.JniManagedPeerState Inherited from Object
IsPlaying IsPlaying

Checks whether the MediaPlayer is playing.

JniIdentityHashCode JniIdentityHashCode Inherited from Object
JniPeerMembers JniPeerMembers
Looping Looping

Checks whether the MediaPlayer is looping or non-looping.

Metrics Metrics
PeerReference PeerReference Inherited from Object
PlaybackParams PlaybackParams
SyncParams SyncParams
ThresholdClass ThresholdClass

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

ThresholdType ThresholdType

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

Timestamp Timestamp
VideoHeight VideoHeight

Returns the height of the video.

VideoWidth VideoWidth

Returns the width of the video.

Methods

AddTimedTextSource(Context, Uri, String) AddTimedTextSource(Context, Uri, String)

Adds an external timed text source file (Uri).

AddTimedTextSource(FileDescriptor, Int64, Int64, String) AddTimedTextSource(FileDescriptor, Int64, Int64, String)

Adds an external timed text file (FileDescriptor).

AddTimedTextSource(FileDescriptor, String) AddTimedTextSource(FileDescriptor, String)

Adds an external timed text source file (FileDescriptor).

AddTimedTextSource(String, String) AddTimedTextSource(String, String)

Adds an external timed text source file.

AttachAuxEffect(Int32) AttachAuxEffect(Int32)

Attaches an auxiliary effect to the player.

Clone() Clone()

Creates and returns a copy of this Object.

(Inherited from Object)
Create(Context, Int32) Create(Context, Int32)

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

Create(Context, Int32, AudioAttributes, Int32) 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) Create(Context, Uri)

Convenience method to create a MediaPlayer for a given Uri.

Create(Context, Uri, ISurfaceHolder) Create(Context, Uri, ISurfaceHolder)

Convenience method to create a MediaPlayer for a given Uri.

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

Deselect a track.

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

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

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

Returns an integer hash code for this object.

(Inherited from Object)
GetKeyRequest(Byte[], Byte[], String, MediaDrmKeyType, IDictionary<String,String>) GetKeyRequest(Byte[], Byte[], String, MediaDrmKeyType, IDictionary<String,String>)
GetSelectedTrack(MediaTrackType) 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() GetTrackInfo()

Returns an array of track information.

JavaFinalize() JavaFinalize()

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

(Inherited from Object)
Notify() 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() 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() Pause()

Pauses playback.

Prepare() Prepare()

Prepares the player for playback, synchronously.

PrepareAsync() PrepareAsync()

Prepares the player for playback, asynchronously.

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

Releases resources associated with this MediaPlayer object.

ReleaseDrm() ReleaseDrm()
Reset() Reset()

Resets the MediaPlayer to its uninitialized state.

RestoreKeys(Byte[]) RestoreKeys(Byte[])
SeekTo(Int32) SeekTo(Int32)

Seeks to specified time position.

SeekTo(Int64, MediaPlayerSeekMode) SeekTo(Int64, MediaPlayerSeekMode)
SelectTrack(Int32) SelectTrack(Int32)

Selects a track.

SetAudioAttributes(AudioAttributes) SetAudioAttributes(AudioAttributes)

Sets the audio attributes for this MediaPlayer.

SetAudioStreamType(Stream) SetAudioStreamType(Stream)

Sets the audio stream type for this MediaPlayer.

SetAuxEffectSendLevel(Single) SetAuxEffectSendLevel(Single)

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

SetDataSource(AssetFileDescriptor) SetDataSource(AssetFileDescriptor)
SetDataSource(Context, Uri) SetDataSource(Context, Uri)

Sets the data source as a content Uri.

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

Sets the data source (FileDescriptor) to use.

SetDataSource(FileDescriptor, Int64, Int64) SetDataSource(FileDescriptor, Int64, Int64)

Sets the data source (FileDescriptor) to use.

SetDataSource(MediaDataSource) SetDataSource(MediaDataSource)
SetDataSource(String) SetDataSource(String)

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

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

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

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

Sets the Handle property.

(Inherited from Object)
SetNextMediaPlayer(MediaPlayer) SetNextMediaPlayer(MediaPlayer)

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

SetOnBufferingUpdateListener(MediaPlayer+IOnBufferingUpdateListener) SetOnBufferingUpdateListener(MediaPlayer+IOnBufferingUpdateListener)

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

SetOnCompletionListener(MediaPlayer+IOnCompletionListener) SetOnCompletionListener(MediaPlayer+IOnCompletionListener)

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

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

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

SetOnInfoListener(MediaPlayer+IOnInfoListener) SetOnInfoListener(MediaPlayer+IOnInfoListener)

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

SetOnPreparedListener(MediaPlayer+IOnPreparedListener) SetOnPreparedListener(MediaPlayer+IOnPreparedListener)

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

SetOnSeekCompleteListener(MediaPlayer+IOnSeekCompleteListener) SetOnSeekCompleteListener(MediaPlayer+IOnSeekCompleteListener)

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

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

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

SetOnVideoSizeChangedListener(MediaPlayer+IOnVideoSizeChangedListener) SetOnVideoSizeChangedListener(MediaPlayer+IOnVideoSizeChangedListener)

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

SetScreenOnWhilePlaying(Boolean) SetScreenOnWhilePlaying(Boolean)

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

SetSurface(Surface) SetSurface(Surface)

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

SetVideoScalingMode(VideoScalingMode) SetVideoScalingMode(VideoScalingMode)

Sets video scaling mode.

SetVolume(Single, Single) SetVolume(Single, Single)

Sets the volume on this player.

SetWakeMode(Context, WakeLockFlags) SetWakeMode(Context, WakeLockFlags)

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

Start() Start()

Starts or resumes playback.

Stop() Stop()

Stops playback after playback has been stopped or paused.

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

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

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

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

(Inherited from Object)
Wait(Int64) 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) 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 BufferingUpdate
Completion Completion
DrmInfoEvent DrmInfoEvent
DrmPrepared DrmPrepared
Error Error
Info Info
Prepared Prepared
SeekComplete SeekComplete
TimedMetaDataAvailable TimedMetaDataAvailable
TimedText TimedText
VideoSizeChanged VideoSizeChanged

Explicit Interface Implementations

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

Extension Methods

JavaCast<TResult>(IJavaObject) JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject) JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable) GetJniTypeName(IJavaPeerable)

Applies to