Class HtmlMediaPlayer
-
- All Implemented Interfaces:
public final class HtmlMediaPlayerHtmlMediaPlayer provides an interface to play video content using ExoPlayer. It handles video loading, playback control, caching, and event tracking.
-
-
Field Summary
Fields Modifier and Type Field Description private final Flow<VideoEvent>mediaPlayerFlow
-
Constructor Summary
Constructors Constructor Description HtmlMediaPlayer(Context context, AdConfig.HybridNativeConfig hybridNativeConfig, CoroutineScope coroutineScope, HtmlVideoPlayerRequest htmlVideoPlayerRequest, InMobiLogger logger)
-
Method Summary
Modifier and Type Method Description final Flow<VideoEvent>getMediaPlayerFlow()A flow of media player events that can be observed by clients. final Unitload()Loads the provided list of video files into the player. final Unitinflate(ViewGroup parentView)Inflates the player view into the provided parent view. final Unitstart()Starts the player by attaching event listeners and playing if autoplay is enabled. final Unitstop()Stops video playback and related tracking components. final Unitdestroy()Destroys the player and releases all associated resources, including ExoPlayer, views, and coroutine scopes. final UnitplayVideo()Starts or resumes video playback. final UnitpauseVideo()Pauses video playback if currently playing. final HtmlVideoPlaybackStategetPlaybackState()Gets a snapshot of the current playback state. final StringgetDurationRelatedPayload()final BooleanisPlaying()A lightweight status flag to check if the player is currently playing. final UnitregisterLastAppTriggeredPlaybackState(PlayerState state)Persists the last playback state that was triggered by an external event (e.g., window visibility change) to allow for correct state restoration. final PlayerStategetLastAppTriggeredPlaybackState()Retrieves the last playback state triggered by an external event. final UnitupdateVideoPosition(VideoViewPosition newVideoViewPosition)Updates the on-screen position and dimensions of the video view. final UnithandleMute(Boolean mute)Controls the mute state of the player's audio. final UnithandleShowPlayer(Boolean show)Shows or hides the player view. -
-
Constructor Detail
-
HtmlMediaPlayer
HtmlMediaPlayer(Context context, AdConfig.HybridNativeConfig hybridNativeConfig, CoroutineScope coroutineScope, HtmlVideoPlayerRequest htmlVideoPlayerRequest, InMobiLogger logger)
-
-
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_PLAYINGstate.
-
getPlaybackState
@MainThread() final HtmlVideoPlaybackState getPlaybackState()
Gets a snapshot of the current playback state.
- Returns:
An HtmlVideoPlaybackState object containing current playback information (playing status, position, duration, muted state).
-
getDurationRelatedPayload
final String getDurationRelatedPayload()
-
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:
trueif the player is active,falseotherwise.
-
registerLastAppTriggeredPlaybackState
final Unit registerLastAppTriggeredPlaybackState(PlayerState state)
Persists the last playback state that was triggered by an external event (e.g., window visibility change) to allow for correct state restoration.
- Parameters:
state- The PlayerState to register.
-
getLastAppTriggeredPlaybackState
final PlayerState getLastAppTriggeredPlaybackState()
Retrieves the last playback state triggered by an external event.
- Returns:
The last registered PlayerState, or null if none.
-
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-trueto mute the player,falseto unmute.
-
handleShowPlayer
final Unit handleShowPlayer(Boolean show)
Shows or hides the player view.
- Parameters:
show-trueto show the player,falseto hide it.
-
-
-
-