Interface NativeMediaPlayer
-
- All Implemented Interfaces:
public interface NativeMediaPlayer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classNativeMediaPlayer.Companion
-
Method Summary
Modifier and Type Method Description abstract UnitsetDataSource(String path)Sets the data source (file-path or http/rtsp URL) to use. abstract Unitprepare()Prepares the player for playback, synchronously. abstract UnitprepareAsync()Prepares the player for playback, asynchronously. abstract UnitseekTo(Integer msec)Seeks to specified time position. abstract Unitstart()Starts or resumes playback. abstract Unitpause()Pauses playback. abstract Unitstop()Stops playback after playback has been started or paused. abstract Unitreset()Resets the MediaPlayer to its uninitialized state. abstract Unitrelease()Releases resources associated with this MediaPlayer object. abstract UnitsetOnCompletionListener(Function0<Unit> listener)Register a callback to be invoked when the end of a media source has been reached during playback. abstract UnitsetOnErrorListener(Function3<NativeMediaPlayer, Integer, Integer, Boolean> listener)Register a callback to be invoked when an error has happened during an asynchronous operation. abstract UnitsetOnPreparedListener(Function0<Unit> listener)Register a callback to be invoked when the media source is ready for playback. abstract FloatgetSpeed()Retrieves/Sets the speed factor. abstract UnitsetSpeed(Float speed)Retrieves/Sets the speed factor. abstract IntegergetCurrentPosition()Gets the current playback position. abstract IntegergetDuration()Gets the duration of the file. -
-
Method Detail
-
setDataSource
abstract Unit setDataSource(String path)
Sets the data source (file-path or http/rtsp URL) to use.
- Parameters:
path- the path of the file, or the http/rtsp URL of the stream you want to play
-
prepare
abstract Unit prepare()
Prepares the player for playback, synchronously.
After setting the datasource and the display surface, you need to either call prepare() or prepareAsync(). For files, it is OK to call prepare(), which blocks until MediaPlayer is ready for playback.
-
prepareAsync
abstract Unit prepareAsync()
Prepares the player for playback, asynchronously.
After setting the datasource and the display surface, you need to either call prepare() or prepareAsync(). For streams, you should call prepareAsync(), which returns immediately, rather than blocking until enough data has been buffered.
-
seekTo
abstract Unit seekTo(Integer msec)
Seeks to specified time position.
- Parameters:
msec- the offset in milliseconds from the start to seek to
-
start
abstract Unit start()
Starts or resumes playback. If playback had previously been paused, playback will continue from where it was paused. If playback had been stopped, or never started before, playback will start at the beginning.
-
reset
abstract Unit reset()
Resets the MediaPlayer to its uninitialized state. After calling this method, you will have to initialize it again by setting the data source and calling prepare().
-
release
abstract Unit release()
Releases resources associated with this MediaPlayer object.
<p>You must call this method once the instance is no longer required.
-
setOnCompletionListener
abstract Unit setOnCompletionListener(Function0<Unit> listener)
Register a callback to be invoked when the end of a media source has been reached during playback.
- Parameters:
listener- the callback that will be run
-
setOnErrorListener
abstract Unit setOnErrorListener(Function3<NativeMediaPlayer, Integer, Integer, Boolean> listener)
Register a callback to be invoked when an error has happened during an asynchronous operation.
- Parameters:
listener- the callback that will be runListener returns True if it handled the error, false if it didn't.
-
setOnPreparedListener
abstract Unit setOnPreparedListener(Function0<Unit> listener)
Register a callback to be invoked when the media source is ready for playback.
- Parameters:
listener- the callback that will be run
-
getSpeed
@RequiresApi(value = 23) abstract Float getSpeed()
Retrieves/Sets the speed factor.
- Returns:
speed
-
setSpeed
@RequiresApi(value = 23) abstract Unit setSpeed(Float speed)
Retrieves/Sets the speed factor.
- Returns:
speed
-
getCurrentPosition
abstract Integer getCurrentPosition()
Gets the current playback position.
- Returns:
the current position in milliseconds
-
getDuration
abstract Integer getDuration()
Gets the duration of the file.
- Returns:
the duration in milliseconds, if no duration is available (for example, if streaming live content), -1 is returned.
-
-
-
-