Android MediaPlayer

Method Name

Valid Sates

Invalid States

Comments

attachAuxEffect

{Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted}

{Idle, Error}

This method must be called after setDataSource. Calling it does not change the object state.

getAudioSessionId

any

{}

This method can be called in any state and calling it does not change the object state.

getCurrentPosition

{Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted}

{Error}

Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state.

getDuration

{Prepared, Started, Paused, Stopped, PlaybackCompleted}

{Idle, Initialized, Error}

Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state.

getVideoHeight

{Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted}

{Error}

Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state.

getVideoWidth

{Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted}

{Error}

Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state.

isPlaying

{Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted}

{Error}

Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state.

pause

{Started, Paused, PlaybackCompleted}

{Idle, Initialized, Prepared, Stopped, Error}

Successful invoke of this method in a valid state transfers the object to the Paused state. Calling this method in an invalid state transfers the object to the Error state.

prepare

{Initialized, Stopped}

{Idle, Prepared, Started, Paused, PlaybackCompleted, Error}

Successful invoke of this method in a valid state transfers the object to the Prepared state. Calling this method in an invalid state throws an IllegalStateException.

prepareAsync

{Initialized, Stopped}

{Idle, Prepared, Started, Paused, PlaybackCompleted, Error}

Successful invoke of this method in a valid state transfers the object to the Preparing state. Calling this method in an invalid state throws an IllegalStateException.

release

any

{}

After release(), the object is no longer available.

reset

{Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted, Error}

{}

After reset(), the object is like being just created.

seekTo

{Prepared, Started, Paused, PlaybackCompleted}

{Idle, Initialized, Stopped, Error}

Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state.

setAudioSessionId

{Idle}

{Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted, Error}

This method must be called in idle state as the audio session ID must be known before calling setDataSource. Calling it does not change the object state.

setAudioStreamType

{Idle, Initialized, Stopped, Prepared, Started, Paused, PlaybackCompleted}

{Error}

Successful invoke of this method does not change the state. In order for the target audio stream type to become effective, this method must be called before prepare() or prepareAsync().

setAuxEffectSendLevel

any

{}

Calling this method does not change the object state.

setDataSource

{Idle}

{Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted, Error}

Successful invoke of this method in a valid state transfers the object to the Initialized state. Calling this method in an invalid state throws an IllegalStateException.

setDisplay

any

{}

This method can be called in any state and calling it does not change the object state.

setSurface

any

{}

This method can be called in any state and calling it does not change the object state.

setVideoScalingMode

{Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted}

{Idle, Error}

Successful invoke of this method does not change the state.

setLooping

{Idle, Initialized, Stopped, Prepared, Started, Paused, PlaybackCompleted}

{Error}

Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state.

isLooping

any

{}

This method can be called in any state and calling it does not change the object state.

setOnBufferingUpdateListener

any

{}

This method can be called in any state and calling it does not change the object state.

setOnCompletionListener

any

{}

This method can be called in any state and calling it does not change the object state.

setOnErrorListener

any

{}

This method can be called in any state and calling it does not change the object state.

setOnPreparedListener

any

{}

This method can be called in any state and calling it does not change the object state.

setOnSeekCompleteListener

any

{}

This method can be called in any state and calling it does not change the object state.

setScreenOnWhilePlaying any

{}

This method can be called in any state and calling it does not change the object state.

setVolume

{Idle, Initialized, Stopped, Prepared, Started, Paused, PlaybackCompleted}

{Error}

Successful invoke of this method does not change the state.
setWakeMode

any

{}

This method can be called in any state and calling it does not change the object state.

start

{Prepared, Started, Paused, PlaybackCompleted}

{Idle, Initialized, Stopped, Error}

Successful invoke of this method in a valid state transfers the object to the Started state. Calling this method in an invalid state transfers the object to the Error state.

stop

{Prepared, Started, Stopped, Paused, PlaybackCompleted}

{Idle, Initialized, Error}

Successful invoke of this method in a valid state transfers the object to the Stopped state. Calling this method in an invalid state transfers the object to the Error state.

getTrackInfo

{Prepared, Started, Stopped, Paused, PlaybackCompleted}

{Idle, Initialized, Error}

Successful invoke of this method does not change the state.

addTimedTextSource

{Prepared, Started, Stopped, Paused, PlaybackCompleted}

{Idle, Initialized, Error}

Successful invoke of this method does not change the state.

selectTrack

{Prepared, Started, Stopped, Paused, PlaybackCompleted}

{Idle, Initialized, Error}

Successful invoke of this method does not change the state.

deselectTrack

{Prepared, Started, Stopped, Paused, PlaybackCompleted}

{Idle, Initialized, Error}

Successful invoke of this method does not change the state.
Public Methods
void addTimedTextSource( Context context,  Uri uri,  String mimeType)
Adds an external timed text source file (Uri).
void addTimedTextSource( String path,  String mimeType)
Adds an external timed text source file.
void addTimedTextSource( FileDescriptor fd, long offset, long length,  String mimeType)
Adds an external timed text file (FileDescriptor).
void addTimedTextSource( FileDescriptor fd,  String mimeType)
Adds an external timed text source file (FileDescriptor).
void attachAuxEffect(int effectId)
Attaches an auxiliary effect to the player.
static  MediaPlayer create( Context context,  Uri uri,  SurfaceHolder holder)
Convenience method to create a MediaPlayer for a given Uri.
static  MediaPlayer create( Context context, int resid)
Convenience method to create a MediaPlayer for a given resource id.
static  MediaPlayer create( Context context,  Uri uri)
Convenience method to create a MediaPlayer for a given Uri.
void deselectTrack(int index)
Deselect a track.
int getAudioSessionId()
Returns the audio session ID.
int getCurrentPosition()
Gets the current playback position.
int getDuration()
Gets the duration of the file.
TrackInfo[] getTrackInfo()
Returns an array of track information.
int getVideoHeight()
Returns the height of the video.
int getVideoWidth()
Returns the width of the video.
boolean isLooping()
Checks whether the MediaPlayer is looping or non-looping.
boolean isPlaying()
Checks whether the MediaPlayer is playing.
void pause()
Pauses playback.
void prepare()
Prepares the player for playback, synchronously.
void prepareAsync()
Prepares the player for playback, asynchronously.
void release()
Releases resources associated with this MediaPlayer object.
void reset()
Resets the MediaPlayer to its uninitialized state.
void seekTo(int msec)
Seeks to specified time position.
void selectTrack(int index)
Selects a track.
void setAudioSessionId(int sessionId)
Sets the audio session ID.
void setAudioStreamType(int streamtype)
Sets the audio stream type for this MediaPlayer.
void setAuxEffectSendLevel(float level)
Sets the send level of the player to the attached auxiliary effect .
void setDataSource( String path)
Sets the data source (file-path or http/rtsp URL) to use.
void setDataSource( Context context,  Uri uri,  Map< StringString> headers)
Sets the data source as a content Uri.
void setDataSource( Context context,  Uri uri)
Sets the data source as a content Uri.
void setDataSource( FileDescriptor fd, long offset, long length)
Sets the data source (FileDescriptor) to use.
void setDataSource( FileDescriptor fd)
Sets the data source (FileDescriptor) to use.
void setDisplay( SurfaceHolder sh)
Sets the  SurfaceHolder to use for displaying the video portion of the media.
void setLooping(boolean looping)
Sets the player to be looping or non-looping.
void setNextMediaPlayer( MediaPlayer next)
Set the MediaPlayer to start when this MediaPlayer finishes playback (i.e.
void setOnBufferingUpdateListener( MediaPlayer.OnBufferingUpdateListener listener)
Register a callback to be invoked when the status of a network stream's buffer has changed.
void setOnCompletionListener( MediaPlayer.OnCompletionListener listener)
Register a callback to be invoked when the end of a media source has been reached during playback.
void setOnErrorListener( MediaPlayer.OnErrorListener listener)
Register a callback to be invoked when an error has happened during an asynchronous operation.
void setOnInfoListener( MediaPlayer.OnInfoListener listener)
Register a callback to be invoked when an info/warning is available.
void setOnPreparedListener( MediaPlayer.OnPreparedListener listener)
Register a callback to be invoked when the media source is ready for playback.
void setOnSeekCompleteListener( MediaPlayer.OnSeekCompleteListener listener)
Register a callback to be invoked when a seek operation has been completed.
void setOnTimedTextListener( MediaPlayer.OnTimedTextListener listener)
Register a callback to be invoked when a timed text is available for display.
void setOnVideoSizeChangedListener( MediaPlayer.OnVideoSizeChangedListener listener)
Register a callback to be invoked when the video size is known or updated.
void setScreenOnWhilePlaying(boolean screenOn)
Control whether we should use the attached SurfaceHolder to keep the screen on while video playback is occurring.
void setSurface( Surface surface)
Sets the  Surface to be used as the sink for the video portion of the media.
void setVideoScalingMode(int mode)
Sets video scaling mode.
void setVolume(float leftVolume, float rightVolume)
Sets the volume on this player.
void setWakeMode( Context context, int mode)
Set the low-level power management behavior for this MediaPlayer.
void start()
Starts or resumes playback.
void stop()
Stops playback after playback has been stopped or paused.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值