All Products
Search
Document Center

:Methods of the ExoPlayer HLS player

Last Updated:Mar 01, 2022

The ExoPlayer HLS player is developed based on the ExoPlayer framework. This topic describes the methods of the ExoPlayer HLS player that LinkVisual SDK for Android provides.

Constructor

ExoHlsPlayer(Context context);

Set a playback source by using an M3U8 URL

/**
   * Set a playback source.
   * @param url The M3U8 URL.
   */
  void setDataSource(String url);

Set a playback source by using the name of a recording file in the cloud

/**
   * Set a playback source by using the name of a recording file in the cloud.
   * @param iotId The ID of the device.
   * @param fileName The name of the recording file.
   */
   void setDataSourceByIPCRecordFileName(String iotId, String fileName);

Validate and prepare data

/**
   * Validate and prepare data.
   */
  void prepare();

Start or resume the playback

/**
   * Start or resume the playback.
   */
  void start();

Pause the playback

/**
   * Pause the playback. You can call the start() method to resume the playback.
   */
  void pause();

Seek to the specified position

/**
   * Seek to the specified position.
   * @param position Unit: milliseconds.
   */
  void seekTo(long positionInMs);

Stop the playback

**
   * Stop the playback.
   */
  void stop();

Reset the player

/**
   * Reset the player.
   */
  void reset();

Release player resources

/**
   * Release player resources.
   */
  void release();

Specify whether to enable loop playback

/**
  * Specify whether to enable loop playback.
  * @param circlePlay A value of true indicates that loop playback is enabled.
  */
  void setCirclePlay(boolean circlePlay);

Set the playback speed

/**
  * Set the playback rate.
  * @param speed The speed factor. Valid values: (0,2]. A value of 1 indicates the original speed.
  */
  void setPlaybackSpeed(float speed);

Set the player volume

/**
   * Set the player volume.
   * @param audioVolume Value range: 0 to 1. A value of 0 indicates the mute mode.
   */
  void setVolume(float audioVolume);

Set the audio stream type

/**
   * Set the audio stream type by referring to {@link android.media.AudioManager}.
   * If the audio is being played, you may experience a brief pause due to audio track recreation.
   * @param audioStreamType
   */
  void setAudioStreamType(int audioStreamType);

Set the scaling mode for video images

/**
   * Set the scaling mode for video images. Default value: {@link android.media.MediaCodec#VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING}.
   * @param videoScalingMode Valid values:
   * {@link android.media.MediaCodec#VIDEO_SCALING_MODE_SCALE_TO_FIT}
   * {@link android.media.MediaCodec#VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING}
   */
  void setVideoScalingMode(int videoScalingMode);

Set a SurfaceView object

/**
   * Set a SurfaceView object.
   * @param surfaceview
   */
  void setSurfaceView(SurfaceView surfaceview);

Clear the SurfaceView object

/**
   * Clear the SurfaceView object.
   */
  void clearSurfaceView();

Set a TextureView object

/**
     * Set a TextureView object. The same TextureView object cannot be shared by multiple player instances. The ZoomableTextureView object that supports gestures is provided for reference.
     * @param textureview
     */
    void setTextureView(TextureView textureView);

Clear the TextureView object

/**
     * Clear the TextureView object.
     */
    void clearTextureView();

Set a listener to listen for whether the data source is ready

/**
   * Set a listener to listen for whether the data source is ready.
   * @param listener
   */
  void setOnPreparedListener(OnPreparedListener listener);

interface OnPreparedListener {
    /**
     * Trigger a callback when the data source is ready.
     */
    void onPrepared();
}

Set a listener to listen for player errors

/**
   * Set a listener to listen for player errors. Error types:
   * {@link PlayerException.SOURCE_ERROR}
   * {@link PlayerException.RENDER_ERROR}
   * {@link PlayerException.UNEXPECTED_ERROR}
   * @param listener
   */
  void setOnErrorListener(OnErrorListener listener);

interface OnErrorListener{
    /**
     * Trigger a callback when a player error occurs. See:
     * {@link PlayerException}
     * @param exception
     */
    void onError(PlayerException exception);
}

Set a listener to listen for player status changes

/**
   * Set a listener to listen for player status changes.
   * @param listener
   */
  void setOnPlayerStateChangedListener(OnPlayerStateChangedListener listener);

interface OnPlayerStateChangedListener{
    /**
     * Trigger a callback when the player status changes.
     *
     * @param playerState Valid values:
     *                    {@link PlayerState#STATE_IDLE}
     *                    {@link PlayerState#STATE_BUFFERING}
     *                    {@link PlayerState#STATE_READY}
     *                    {@link PlayerState#STATE_ENDED}
     */
    void onPlayerStateChange(int playerState);
}

Set a listener to listen for whether the first frame is rendered

/**
   * Set a listener to listen for whether the first frame is rendered.
   * @param listener
   */
  void setOnRenderedFirstFrameListener(OnRenderedFirstFrameListener listener);

 interface OnRenderedFirstFrameListener {
    /**
     * Trigger a callback when the first frame is rendered.
     */
    void onRenderedFirstFrame();
}

Set a listener to listen for whether the width and height of a video are adjusted

    /**
     * Set a listener to listen for whether the width and height of a video are adjusted.
     * @param listener
     */
    void setOnVideoSizeChangedListener(OnVideoSizeChangedListener listener);

 interface OnVideoSizeChangedListener{

    /**
     * Trigger a callback when the width and height of a video are adjusted.
     *
     * @param width The width of the video. Unit: pixel.
     * @param height The height of the video. Unit: pixel.
     */
    void onVideoSizeChanged(int width, int height);
}

Obtain the current playback position

/**
   * Obtain the current playback position, which is the offset from the start position of the video.
   * The getCurrentPosition method is valid only if the player status is {@link PlayerState#STATE_READY}.
   * @return Unit: milliseconds.
   */
  long getCurrentPosition();

Obtain the total duration of a video

/**
   * Obtain the total duration of a video.
   * The getDuration method is valid only if the player status is {@link PlayerState#STATE_READY}.
   * @return Unit: milliseconds.
   */
  long getDuration();

Obtain the player volume

/**
   * Obtain the player volume.
   * @return Valid values: 0 to 1.
   */
  float getVolume();

Obtain the player status

/**
   * Obtain the player status.
   * @return Valid values:
   * {@link PlayerState#STATE_IDLE}: The player is in the initial state.
   * {@link PlayerState#STATE_BUFFERING}: The player is buffering content.
   * {@link PlayerState#STATE_READY}: The buffering is complete, and the player starts to play content.
   * {@link PlayerState#STATE_ENDED}: The playback ends.
   */
  int getPlayState();

ZoomableTextureView-related methods

Set the maximum magnification scale for video images

    /**
     * Set the maximum magnification scale for video images.
     * Default value: 4×.
     *
     * @param scale The magnification scale.
     */
    void setMaxScale(float scale);

Reset the image scaling ratio to 1

    /**
     * Reset the image scaling ratio to 1.
     *
     * @param smooth Specify whether smooth image scaling is enabled.
     */
    void zoomOut(boolean smooth);

Obtain the current image scaling ratio

    /**
     * Obtain the current image scaling ratio.
     *
     * @return If the image is not zoomed in or out, the return value is 1.0f.
     */
    float getScale();

Set listeners

    /* Set listeners.
     * @param listener
     */
    void setOnZoomableTextureListener(OnZoomableTextureListener listener);

    public interface OnZoomableTextureListener{

        /**
         * Trigger a callback when the image scaling ratio changes.
         *
         * @param zoomableTextureView
         * @param scale The image scaling ratio.
         */
        void onScaleChanged(ZoomableTextureView zoomableTextureView, float scale);

        /**
         * Trigger a callback when a double-click event occurs in the view object.
         *
         * @param zoomableTextureView
         * @param e                   MotionEvent
         * @return The return value indicates whether the event is handled. If the return value is false, internal scaling logic is used.
         */
        boolean onDoubleTap(ZoomableTextureView zoomableTextureView, MotionEvent e);

        /**
         * Trigger a callback when a single-click event occurs in the view object.
         *
         * @param zoomableTextureView
         * @param e                   MotionEvent
         * @return The return value indicates whether the event is handled.
         */
        boolean onSingleTapConfirmed(ZoomableTextureView zoomableTextureView, MotionEvent e);

        /**
         * Trigger a callback when a long-press event occurs in the view object.
         *
         * @param zoomableTextureView
         * @param e                   MotionEvent
         */
        void onLongPress(ZoomableTextureView zoomableTextureView, MotionEvent e);
    }

Set edge listeners


     void setOnViewEdgeListener(OnViewEdgeListener listener)

     interface OnViewEdgeListener{

        /**
         * Trigger a callback when you tap an edge of the view object for the first time.
         */
        void onViewEdgeFirstTouched();

        /**
         * A callback keeps being triggered if you constantly tap the lower edge of the view object.
         *
         * @param zoomableTextureView
         * @param delta The offset relative to the last tap point if you constantly tap the lower edge of the view object.
         */
        void onBottomEdge(ZoomableTextureView zoomableTextureView, float delta);

        /**
         * A callback keeps being triggered if you constantly tap the upper edge of the view object.
         *
         * @param zoomableTextureView
         * @param delta The offset relative to the last tap point if you constantly tap the upper edge of the view object.
         */
        void onTopEdge(ZoomableTextureView zoomableTextureView, float delta);

        /**
         * A callback keeps being triggered if you constantly tap the right edge of the view object.
         *
         * @param zoomableTextureView
         * @param delta The offset relative to the last tap point if you constantly tap the right edge of the view object.
         */
        void onRightEdge(ZoomableTextureView zoomableTextureView, float delta);

        /**
         * A callback keeps being triggered if you constantly tap the left edge of the view object.
         *
         * @param zoomableTextureView
         * @param delta The offset relative to the last tap point if you constantly tap the left edge of the view object.
         */
        void onLeftEdge(ZoomableTextureView zoomableTextureView, float delta);
    }