VPAID Playback Activity

Purpose

The VPAID Playback Activity is responsible for managing the lifecycle and setup of the WebView-based VPAID ad player within the media playback system. While the broader VPAID Ad Integration subtopic focuses on implementing the VPAID client logic and JavaScript communication, this activity specifically provides the Android UI container and environment that hosts the VPAID ads. It ensures proper initialization, visibility, and interaction of the WebView component that renders VPAID ads, bridging the gap between the VPAID client and the Android activity lifecycle.

Functionality

Critical Code Interaction

webView.addJavascriptInterface(tubiVPAID, "TubiNativeJSInterface");
webView.loadUrl(VPAID_URL);

This snippet shows how the `TubiVPAID` client is exposed to JavaScript running inside the WebView, enabling two-way communication necessary for VPAID ad interactions.

Integration with Parent Topic and Other Subtopics

By isolating WebView lifecycle management in this dedicated activity, the system maintains modularity: the FSM playback and ad logic remain focused on state transitions and media control, while the activity manages UI rendering and user navigation during VPAID ad playback.

Diagram

sequenceDiagram
    participant Activity as WebviewActivity
    participant WebView as Android WebView
    participant VPAID as TubiVPAID Client
    participant JS as VPAID JavaScript

    Activity->>WebView: findViewById()
    Activity->>VPAID: new TubiVPAID(WebView, Handler)
    Activity->>WebView: addJavascriptInterface(VPAID, "TubiNativeJSInterface")
    Activity->>WebView: loadUrl(VPAID_URL)
    WebView->>JS: Load VPAID Ad Content
    JS->>VPAID: Call Native JS Interface Methods (e.g. AdFinished)
    VPAID->>Activity: Notify Ad Events (via Handler callbacks)
    Activity->>WebView: Handle Back Press (goBack or finish)

This sequence diagram illustrates the core process of initializing the WebView, binding the VPAID client as a JavaScript interface, loading the ad content, and handling bidirectional communication between JavaScript and native Android code during ad playback. It also shows how user navigation inputs like the back button are managed within the activity.