VpaidState.java


Overview

`VpaidState.java` defines the **VpaidState** class, a concrete state within the media player's finite state machine (FSM) responsible for handling playback of **VPAID (Video Player Ad-Serving Interface Definition)** ads. VPAID ads are interactive advertisements played inside a WebView rather than a standard video player.

This state manages pausing all existing ExoPlayer instances (both content and ad players), initializing the VPAID client with the next ad, making the WebView visible to display the interactive VPAID ad, and hiding other UI components such as subtitles and the main video view. It also defines transitions from this state based on input events related to VPAID ad playback.


Detailed Class Explanation

Class: VpaidState

public class VpaidState extends BaseState

Key Methods

1. transformToState

@Override
public State transformToState(Input input, StateFactory factory)

Input

Resulting State

Description

`VPAID_FINISH`

`MoviePlayingState`

VPAID ad finished, resume main movie playback.

`VPAID_MANIFEST`

`VpaidState`

Possibly reload or refresh VPAID ad manifest.

`NEXT_AD`

`AdPlayingState`

Transition to next standard ad playback.

*default*

`null`

No valid transition; FSM remains in current state.

State nextState = vpaidState.transformToState(Input.VPAID_FINISH, stateFactory);
if (nextState != null) {
    fsmPlayer.setCurrentState(nextState);
}

2. performWorkAndUpdatePlayerUI

@Override
public void performWorkAndUpdatePlayerUI(@NonNull FsmPlayer fsmPlayer)

3. pausePlayerAndSHowVpaid

private void pausePlayerAndSHowVpaid(
    PlayerUIController controller,
    PlayerAdLogicController componentController,
    FsmPlayer fsmPlayer,
    AdMediaModel adMedia)

Implementation Details and Algorithms


Interaction with Other System Parts


Usage Example

// Assuming FSM player is currently in VpaidState
VpaidState vpaidState = new VpaidState();
StateFactory factory = new StateFactory();

// Transition example based on input
State nextState = vpaidState.transformToState(Input.VPAID_FINISH, factory);
if (nextState != null) {
    fsmPlayer.setCurrentState(nextState);
    nextState.performWorkAndUpdatePlayerUI(fsmPlayer);
}

// Within the FSM loop, performWorkAndUpdatePlayerUI is called automatically
vpaidState.performWorkAndUpdatePlayerUI(fsmPlayer);

Mermaid Class Diagram

classDiagram
    class VpaidState {
        +transformToState(input: Input, factory: StateFactory): State
        +performWorkAndUpdatePlayerUI(fsmPlayer: FsmPlayer): void
    }
    VpaidState --|> BaseState
    BaseState <|-- VpaidState

Summary

`VpaidState.java` is a concise but crucial part of the media playback FSM responsible for integrating VPAID interactive ads into the native playback experience via a WebView. It handles pausing other video players, initializing the VPAID client with the correct ad, managing UI visibility, and processing state transitions triggered by VPAID ad lifecycle events. This design allows the media player to seamlessly switch between standard video ads, interactive VPAID ads, and main content playback while maintaining a clean and modular finite state machine architecture.