GuidesAPI ReferenceRelease Notes
HomeLog InHome
Guides

Compose-Based Inline Player State Handler

This section covers the state handler constructor and parameters for managing the Compose-based inline video player.

BlazeVideosInlinePlayerComposeStateHandler is a state handler class for managing and facilitating the playback of inline videos in a Compose environment, based on a specified data source type. It acts as the single source of truth for player state, ensuring that recompositions are minimized and state is preserved across the component tree.

Constructor

Constructor

Creates a new instance of BlazeVideosInlinePlayerComposeStateHandler for Compose-based implementation

class BlazeVideosInlinePlayerComposeStateHandler @JvmOverloads constructor(
    dataSource: BlazeDataSourceType,
    playerDelegate: BlazePlayerInInlineDelegate,
    containerId: String,
    playerMode: BlazeVideosInlinePlayer.PlayerMode,
    cachePolicyLevel: BlazeCachingLevel,
    videosAdsConfigType: BlazeVideosAdsConfigType = BlazeVideosAdsConfigType.FIRST_AVAILABLE_ADS_CONFIG,
)

Example

val playerMode = BlazeVideosInlinePlayer.PlayerMode.Interactive(
    interactivePlayerStyle = BlazeVideosInlineInteractivePlayerStyle.base(),
    fullScreenPlayerStyle = BlazeVideosPlayerStyle.base()
)

val stateHandler = BlazeVideosInlinePlayerComposeStateHandler(
    dataSource = BlazeDataSourceType.Labels(BlazeWidgetLabel.singleLabel("videos")),
    playerDelegate = object: BlazePlayerInInlineDelegate {
        //Here is your optional implementation
    },
    containerId = "unique-video-player-id", // ← Must be unique per instance
    playerMode = playerMode,
    cachePolicyLevel = BlazeCachingLevel.DEFAULT
)

Properties

dataSource

dataSource: BlazeDataSourceType

The data source that defines what video content to load in the inline player. Built with BlazeDataSourceType.

Determines the video content filtering and selection for the inline player.

playerDelegate

playerDelegate: BlazePlayerInInlineDelegate

The delegate object for receiving callbacks and events from the inline player.

For detailed information about available delegate methods and event handling, see Event Delegate Documentation.

containerId

containerId: String

Unique identifier for the inline player instance. This identifier MUST be unique per player instance in the app.

playerMode

playerMode: BlazeVideosInlinePlayer.PlayerMode

Determines the presentation mode and behavior of the inline player. Choose between Preview and Interactive modes.

For detailed information about player modes, available options, and configuration, see Player Mode Documentation.

cachePolicyLevel

cachePolicyLevel: BlazeCachingLevel

The cache policy level for this player instance. Defaults to the global SDK caching level.

Overrides the global caching policy for this specific player. Read more about available options in the BlazeCachingLevel documentation.

videosAdsConfigType

videosAdsConfigType: BlazeVideosAdsConfigType = BlazeVideosAdsConfigType.FIRST_AVAILABLE_ADS_CONFIG

The ads configuration for this player instance. Defaults to BlazeVideosAdsConfigType.FIRST_AVAILABLE_ADS_CONFIG.

Controls how ads are displayed and managed within the inline player. Read more about available options in the BlazeVideosAdsConfigType documentation.

State Handler Usage

Once you have created the state handler, you attach it to the composable and it becomes responsible for controlling all player behavior. Instead of directly manipulating the BlazeVideosInlinePlayerCompose, you control the player through the state handler's methods.

@Composable
fun VideoPlayerScreen() {
    val stateHandler = remember {
        BlazeVideosInlinePlayerComposeStateHandler(
            dataSource = dataSource,
            playerDelegate = playerDelegate,
            containerId = "video-player",
            playerMode = playerMode
        )
    }
    
    // Attach state handler to composable
    BlazeVideosInlinePlayerCompose(stateHandler = stateHandler)
    
    // Control player through state handler methods
    LaunchedEffect(Unit) {
        stateHandler.embedPlaceholder()
    }
    
    Button(onClick = { 
        stateHandler.embedPlayer(shouldAutoPlayOnStart = true) 
    }) {
        Text("Start Playing")
    }
}

For complete method documentation and usage examples, see StateHandler Methods.

Important Considerations

Unique Container IDs

Each state handler instance must be associated with a unique containerId to ensure proper management and avoid conflicts.

// ✅ Correct: Unique IDs for different instances
val stateHandler1 = BlazeVideosInlinePlayerComposeStateHandler(
    containerId = "video-player-1",
    // ... other parameters
)

val stateHandler2 = BlazeVideosInlinePlayerComposeStateHandler(
    containerId = "video-player-2", 
    // ... other parameters
)

State Handler Creation

Be mindful of where you create the BlazeVideosInlinePlayerComposeStateHandler depending on your use case. The creation scope affects lifecycle and recomposition behavior. Each BlazeVideosInlinePlayerCompose instance should have a unique BlazeVideosInlinePlayerComposeStateHandler.

// Consider your use case when choosing creation scope
@Composable
fun VideoPlayerScreen() {
    val stateHandler = remember {
        BlazeVideosInlinePlayerComposeStateHandler(...)
    }
    
    BlazeVideosInlinePlayerCompose(stateHandler = stateHandler)
}

Did this page help you?