Skip to content

Widget plugin

A widget plugin can be used to embed native UI inside the overlay.

An embed layer is created in the Studio project, configured with the name of the widget to use. The widget plugin registers itself as the renderer of that layer by specifying the same name in its componentName property. When the overlay creates the layer the plugin's install function is called, where it can add its own subviews.

Implementation

Create a class implementing WidgetPlugin interface.

String getComponentName()

Set to same name that was configured on the embed layer in the Studio project, in which the widget will show.

void install(FrameLayout container, WidgetData data);

Called when the layer will be created in the overlay. Here you can add your views to the contaiener.

AttributeDescriptionType
containerEmbed layer's view in which to add your viewsFrameLayout
dataInformation about the current overlayWidgetData
data.accountIdAccount ID of the overlayString
data.projectIdProject ID of the overlayString
data.programIdProgram ID of the overlayString
data.envEnvironment of the overlay ("prod","staging","dev")String
data.paramsOther parameters passed to the current loaded overlayHashMap<String,String>
data.embedDataData configured on the embed layer in the Studio projectHashMap<String,String>

void show()

Called when the layer will be shown in the overlay

void hide()

Called when the layer will be hidden in the overlay

void destroy()

Called when the container layer will be removed

void onPlayerTime(long time)

Called when time changes in the player. The value is UTC time in milliseconds since 1970-01-01. Can be used to sync timed data shown in the widget.

void onPlayerState(PlayerState state)

Called when player state changes.

Usage

Register widget plug-in after instantiating EaseLive, but before create is called

swift
easeLive = EaseLive(...)
// register before create easeLive.create
easeLive.use(new MyCustomWidget())
easeLive.create()

Example

kotlin
class MyCustomWidget: WidgetPlugin {
    override fun getComponentName(): String {
        return "myCustomWidget"
    }

    override fun install(container: FrameLayout, data: WidgetData) {
        val button = Button(container.context)
        button.isFocusable = true
        button.isFocusableInTouchMode = true
        button.text = "my button"

        container.addView(
            button,
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT
        )
    }

    override fun show() {
        // called when the layer will be shown in the overlay
        // start data updating, animations, etc
    }

    override fun hide() {
        // called when the layer will be hidden in the overlay
        // stop data updating, animations, etc
    }

    override fun destroy() {
        // called when the container layer will be removed
    }

    override fun onPlayerTime(time: Long) {
        // player's absolute time in milliseconds since 1970-01-01T00:00:00Z.
        // can be used to sync timed data shown in the widget
    }

    override fun onPlayerState(state: PlayerState) {
        if (state == PlayerState.PLAYING) {
            // video is playing
        }
    }
}

easeLive = EaseLive(easeLiveView,
                    accountId,
                    projectId,
                    programId)

// register widget plug-in before create
easeLive.use(new MyCustomWidget())

easeLive.create()