Package 

Interface NativeMediaPlayer


  • 
    public interface NativeMediaPlayer
    
                        

    Defines the contract for communicating with a native media player implementation (ex. ExoPlayer).

    • Method Summary

      Modifier and Type Method Description
      abstract Unit setDataSource(String path) Sets the data source (file-path or http/rtsp URL) to use.
      abstract Unit prepareAsync() Prepares the player for playback, asynchronously.
      abstract Unit seekTo(Integer msec) Seeks to specified time position.
      abstract Unit start() Starts or resumes playback.
      abstract Unit pause() Pauses playback.
      abstract Unit stop() Stops playback after playback has been started or paused.
      abstract Unit reset() Resets the MediaPlayer to its uninitialized state.
      abstract Unit release() Releases resources associated with this MediaPlayer object.
      abstract Unit setOnCompletionListener(Function0<Unit> listener) Register a callback to be invoked when the end of a media source has been reached during playback.
      abstract Unit setOnErrorListener(Function1<Integer, Boolean> listener) Register a callback to be invoked when an error has happened during an asynchronous operation.
      abstract Unit setOnPreparedListener(Function0<Unit> listener) Register a callback to be invoked when the media source is ready for playback.
      abstract Float getSpeed() Retrieves/Sets the speed factor.
      abstract Unit setSpeed(Float speed) Retrieves/Sets the speed factor.
      abstract NativeMediaPlayerState getState() Gets the current player state.
      abstract Integer getCurrentPosition() Gets the current playback position.
      abstract Integer getDuration() Gets the duration of the file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
      • 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.

      • pause

         abstract Unit pause()

        Pauses playback. Call start() to resume.

      • stop

         abstract Unit stop()

        Stops playback after playback has been started or paused.

      • 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(Function1<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

         abstract Float getSpeed()

        Retrieves/Sets the speed factor.