MediaPlayerAdapter
class MediaPlayerAdapter : PlayerAdapter
This implementation extends the PlayerAdapter with a MediaPlayer.
Summary
Public constructors |
|---|
MediaPlayerAdapter(context: Context!)Constructor. |
Public functions |
|
|---|---|
Long |
Returns the current buffered position of the media item in milliseconds. |
Long |
Returns the current position of the media item in milliseconds. |
Long |
Returns the duration of the media item in milliseconds. |
MediaPlayer! |
Return the MediaPlayer associated with the MediaPlayerAdapter. |
Int |
Return updating interval of progress UI in milliseconds. |
Boolean |
Returns true if media is currently playing. |
Boolean |
|
Unit |
onAttachedToHost(host: PlaybackGlueHost)This method is called attached to associated |
Unit |
This method is called when current associated |
Unit |
pause()Pauses the media player. |
Unit |
play()Starts the media player. |
Unit |
release()Release internal MediaPlayer. |
Unit |
reset()Will reset the |
Unit |
Seek to new position. |
Boolean |
setDataSource(uri: Uri!)Sets the media source of the player witha given URI. |
Unit |
setProgressUpdatingEnabled(enable: Boolean)Implement this method to enable or disable progress updating. |
Protected functions |
|
|---|---|
Boolean |
Called to indicate an error. |
Boolean |
Called to indicate an info or a warning. |
Unit |
Called to indicate the completion of a seek operation. |
Inherited functions |
||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
Public functions
getBufferedPosition
fun getBufferedPosition(): Long
Returns the current buffered position of the media item in milliseconds.
getCurrentPosition
fun getCurrentPosition(): Long
Returns the current position of the media item in milliseconds.
getMediaPlayer
fun getMediaPlayer(): MediaPlayer!
Return the MediaPlayer associated with the MediaPlayerAdapter. App can use the instance to config DRM or control volumes, etc. Warning: App should not use the following seven listeners as they are controlled by MediaPlayerAdapter. If that's the case, app should write its own PlayerAdapter class. setOnPreparedListenersetOnVideoSizeChangedListenersetOnErrorListenersetOnSeekCompleteListenersetOnCompletionListenersetOnInfoListenersetOnBufferingUpdateListener
| Returns | |
|---|---|
MediaPlayer! |
The MediaPlayer associated with the MediaPlayerAdapter. |
getProgressUpdatingInterval
fun getProgressUpdatingInterval(): Int
Return updating interval of progress UI in milliseconds. Subclass may override.
| Returns | |
|---|---|
Int |
Update interval of progress UI in milliseconds. |
isPrepared
fun isPrepared(): Boolean
| Returns | |
|---|---|
Boolean |
True if MediaPlayer OnPreparedListener is invoked and got a SurfaceHolder if |
onAttachedToHost
fun onAttachedToHost(host: PlaybackGlueHost): Unit
This method is called attached to associated PlaybackGlueHost.
| Parameters | |
|---|---|
host: PlaybackGlueHost |
onDetachedFromHost
fun onDetachedFromHost(): Unit
This method is called when current associated PlaybackGlueHost is attached to a different PlaybackGlue or PlaybackGlueHost is destroyed. Subclass may override. A typical implementation will release resources (e.g. MediaPlayer or connection to playback service) in this method.
release
fun release(): Unit
Release internal MediaPlayer. Should not use the object after call release().
reset
fun reset(): Unit
Will reset the MediaPlayer and the glue such that a new file can be played. You are not required to call this method before playing the first file. However you have to call it before playing a second one.
seekTo
fun seekTo(positionInMs: Long): Unit
Seek to new position.
| Parameters | |
|---|---|
positionInMs: Long |
New position in milliseconds. |
setDataSource
fun setDataSource(uri: Uri!): Boolean
Sets the media source of the player witha given URI.
| Returns | |
|---|---|
Boolean |
Returns |
| See also | |
|---|---|
setDataSource |
setProgressUpdatingEnabled
fun setProgressUpdatingEnabled(enable: Boolean): Unit
Implement this method to enable or disable progress updating.
| Parameters | |
|---|---|
enable: Boolean |
True to enable progress updating, false otherwise. |
Protected functions
onError
protected fun onError(what: Int, extra: Int): Boolean
Called to indicate an error.
| Parameters | |
|---|---|
what: Int |
the type of error that has occurred: |
extra: Int |
an extra code, specific to the error. Typically implementation dependent.
|
| Returns | |
|---|---|
Boolean |
True if the method handled the error, false if it didn't. Returning false, will cause the |
onInfo
protected fun onInfo(what: Int, extra: Int): Boolean
Called to indicate an info or a warning.
| Parameters | |
|---|---|
what: Int |
the type of info or warning.
|
extra: Int |
an extra code, specific to the info. Typically implementation dependent. |
| Returns | |
|---|---|
Boolean |
True if the method handled the info, false if it didn't. Returning false, will cause the info to be discarded. |
onSeekComplete
protected fun onSeekComplete(): Unit
Called to indicate the completion of a seek operation.