Compose-Based Inline Player State Handler Methods
This section covers all available methods for controlling the Compose-based inline video player through the state handler.
BlazeVideosInlinePlayerComposeStateHandler provides methods to control the inline video player within a Compose environment. These methods mirror the functionality of the view-based BlazeVideosInlinePlayer while being optimized for Compose usage patterns.
Methods
prepareVideos
method signature
fun prepareVideos(
completion: (BlazeResult<Unit>) -> Unit = { }
)Prepares videos for playback based on the properties defined in the state handler. This function can be called to ensure that the content is ready in advance. If not called, the content will be prepared when embedding the player.
Parameters:
- completion: A callback that is invoked when the preparation is complete.
embedPlaceholder
method signature
fun embedPlaceholder()Creates placeholder view from the viewing history if available.
Shows static preview representing user's last viewing session. Uses snapshot from last position or preview image.
When to call:
- Loading feed item that was previously viewed
- Transitioning from active player to preview
- Implementing lazy loading for performance
State behavior:
- From active player → Dismiss player, shows placeholder
- From empty → Creates placeholder directly
Result: Static preview with click interaction, no resource consumption
embedPlayer
method signature
fun embedPlayer(
shouldAutoPlayOnStart: Boolean = true,
)Embeds an active player in the inline container.
Replaces any existing placeholder with a functional video player.
When to call:
- User clicks placeholder to start playback
- Programmatically activating player in feed
- Restoring player after configuration changes
State behavior:
- From placeholder → Creates active player
- From empty → Creates player directly
Result: Player ready for immediate interaction and playback
Parameters:
- shouldAutoPlayOnStart: Whether the player should automatically start playback when embedded
resetToPlaceholder
method signature
fun resetToPlaceholder()Resets inline container to clean placeholder state.
Removes active player and creates fresh placeholder with updated viewing data.
When to call:
- User dismisses or closes player
- Scrolling away for resource cleanup
State behavior:
- From active player → Removes player, creates fresh placeholder
Resource management: Stops playback, releases resources, saves viewing progress
Result: Updated placeholder with latest progress, resources released
disposeContainer
method signature
fun disposeContainer()Disposes the inline container and releases all resources.
Permanently cleans up the container, releasing all players, placeholders, and associated resources.
When to call:
- Container no longer needed
- Fragment/Activity destruction
- Memory cleanup operations
- Permanent removal from feed
What happens:
- Stops all active playback
- Releases all media resources
- Clears viewing records and cache
- Removes all views from inline container
- Cancels ongoing operations
Result: Inline container fully disposed, all resources released
resumePlayer
method signature
fun resumePlayer()Resumes player playback and removes any pause lock.
Resumes playback and allows normal lifecycle events and other controls to manage the player state again. Removes any "pause lock" created by pausePlayer().
Behavior after resume:
- Player starts playing immediately
- Lifecycle events can pause/resume the player normally
- Other programmatic controls work normally
- User can pause/resume if UI interaction is enabled
Use cases: Item becomes visible, app returns from background, autoplay scenarios
pausePlayer
method signature
fun pausePlayer()Pauses player playback and creates a "pause lock".
Pauses the player and prevents it from resuming until either:
resumePlayer()is called programmatically, OR- User manually resumes (only if UI interaction is not blocked)
Pause lock behavior:
- Lifecycle events cannot resume the player
- Other programmatic events cannot resume the player
- Player stays paused until explicitly unlocked
Lock can be removed by:
- Calling
resumePlayer()programmatically - User manual resume (if
blockInteraction()not active)
Use cases: Item scrolls away, app goes to background, resource conservation
blockInteraction
method signature
fun blockInteraction()Blocks user interaction with player controls.
Disables all player UI controls while preserving current playback state. When blocked, users cannot override pausePlayer()/resumePlayer() calls. Programmatic control methods still work. Use unblockInteraction() to restore.
Use cases: Loading states, preview-only mode, programmatic sequences
unblockInteraction
method signature
fun unblockInteraction()Restores user interaction with player controls.
Re-enables all player UI controls after blockInteraction(). Users can now manually override pausePlayer()/resumePlayer() states.
Use cases: After loading completes, transitioning to interactive mode
enterFullScreen
method signature
fun enterFullScreen()Enters full screen player mode.
This method is used to switch the player to full screen mode if it's currently in inline mode.
onVolumeChanged
method signature
fun onVolumeChanged()Notifies the player of volume changes.
Updates player's internal volume state and UI indicators. Call when detecting volume key presses or programmatic volume changes.
Use cases: Volume key events, audio focus changes, programmatic volume updates
Integration with Compose Effects and State Hoisting
State handler methods are designed to work seamlessly with Compose side effects and state hoisting patterns. This is the recommended approach for controlling the player in a Compose environment:
@Composable
fun VideoPlayerWithEffects(shouldAutoPlay: Boolean) {
val stateHandler = remember { ... }
// Prepare content when composable is first created
LaunchedEffect(Unit) {
stateHandler.prepareVideos()
}
// Respond to parameter changes
LaunchedEffect(shouldAutoPlay) {
if (shouldAutoPlay) {
stateHandler.embedPlayer(shouldAutoPlayOnStart = true)
} else {
stateHandler.embedPlaceholder()
}
}
// Cleanup when leaving composition
DisposableEffect(Unit) {
onDispose {
stateHandler.disposeContainer()
}
}
BlazeVideosInlinePlayerCompose(stateHandler = stateHandler)
}Static Methods
prepareVideos (Static)
method signature
fun prepareVideos(
containerId: String,
dataSource: BlazeDataSourceType,
shouldOrderContentsByReadStatus: Boolean = true,
cachePolicyLevel: BlazeCachingLevel = BlazeSDK.cachingLevel
)Static method for preparing video content. This is the same static method available in the view-based implementation.
Prepare video content for a specific dataSource type - static method.
This static method preloads videos for the given dataSource, which is built using BlazeDataSourceType.
Important: BlazeRecommendationsType.FOR_YOU is unsupported for preparation and throws a onDataLoadComplete error. This type of data source should be used only to play content directly, using the embedPlayer method.
Parameters:
- containerId: Represents the identifier of the inline player container. This identifier MUST be unique per instance in the app.
- dataSource: Represents the dataSourceType associated with the inline player container. dataSourceType is built with
BlazeDataSourceType. - shouldOrderContentsByReadStatus: Controls whether videos should be ordered by their read status. Takes effect only when repository is clean/fresh (after disposal, first load, or when data source changes). During normal operations, content order remains stable regardless of this setting. Defaults to true.
- cachePolicyLevel: Represents the cache policy level of the inline player container. Defaults to The policy level that was defined in the global level.
Usage Examples
Basic State Handler Usage
@Composable
fun SimpleVideoPlayer() {
val stateHandler = remember {
BlazeVideosInlinePlayerComposeStateHandler(
dataSource = BlazeDataSourceType.Labels(BlazeWidgetLabel.singleLabel("videos")),
playerDelegate = myDelegate,
containerId = "simple-video-player",
playerMode = BlazeVideosInlinePlayer.PlayerMode.Interactive(
interactivePlayerStyle = BlazeVideosInlineInteractivePlayerStyle.base()
),
cachePolicyLevel = BlazeCachingLevel.DEFAULT
)
}
Column {
BlazeVideosInlinePlayerCompose(
modifier = Modifier
.fillMaxWidth()
.aspectRatio(16f / 9f),
stateHandler = stateHandler
)
Row {
Button(onClick = { stateHandler.embedPlaceholder() }) {
Text("Show Placeholder")
}
Button(onClick = { stateHandler.embedPlayer() }) {
Text("Start Player")
}
Button(onClick = { stateHandler.pausePlayer() }) {
Text("Pause")
}
Button(onClick = { stateHandler.resumePlayer() }) {
Text("Resume")
}
}
}
}Updated about 2 months ago
