Class HtmlMediaPlayer

  • All Implemented Interfaces:

    
    public final class HtmlMediaPlayer
    
                        

    HtmlMediaPlayer provides an interface to play video content using ExoPlayer. It handles video loading, playback control, caching, and event tracking.

    • Method Detail

      • getMediaPlayerFlow

         final Flow<VideoEvent> getMediaPlayerFlow()

        A flow of media player events that can be observed by clients. Emits various VideoEvent types during the lifecycle of video playback.

      • load

         final Unit load()

        Loads the provided list of video files into the player. This method initiates the loading process and emits relevant events through mediaPlayerFlow.

      • inflate

        @MainThread() final Unit inflate(ViewGroup parentView)

        Inflates the player view into the provided parent view. This is a safe no-op (with a warning log) if called before a successful load.

        Parameters:
        parentView - The ViewGroup to inflate the player into.
      • start

         final Unit start()

        Starts the player by attaching event listeners and playing if autoplay is enabled. Should be called after load and inflate.

      • stop

         final Unit stop()

        Stops video playback and related tracking components. This is a safe no-op if the player is not currently playing. It does not release resources, but pauses active operations.

      • destroy

         final Unit destroy()

        Destroys the player and releases all associated resources, including ExoPlayer, views, and coroutine scopes. Call this method when the player is no longer needed to prevent memory leaks.

      • playVideo

         final Unit playVideo()

        Starts or resumes video playback. If the video has completed, calling this will restart playback from the beginning.

      • pauseVideo

         final Unit pauseVideo()

        Pauses video playback if currently playing. This is a safe no-op if the player is not in the STATE_PLAYING state.

      • isPlaying

        @MainThread() final Boolean isPlaying()

        A lightweight status flag to check if the player is currently playing. Useful for quick visibility integrations without fetching the full playback state.

        Returns:

        true if the player is active, false otherwise.

      • updateVideoPosition

         final Unit updateVideoPosition(VideoViewPosition newVideoViewPosition)

        Updates the on-screen position and dimensions of the video view. This method re-applies layout parameters and requests a layout pass to reflect changes, while preserving the video's aspect ratio.

        Parameters:
        newVideoViewPosition - The new position and size parameters to apply.
      • handleMute

         final Unit handleMute(Boolean mute)

        Controls the mute state of the player's audio.

        Parameters:
        mute - true to mute the player, false to unmute.
      • handleShowPlayer

         final Unit handleShowPlayer(Boolean show)

        Shows or hides the player view.

        Parameters:
        show - true to show the player, false to hide it.