AdPlayingState.java


Overview

`AdPlayingState.java` defines the **AdPlayingState** class, a concrete playback state within a finite state machine (FSM) controlling video playback in the media player system. This state is responsible for managing the playback of video advertisements, including preparing the ad player, pausing main content, handling VPAID ads, updating the UI accordingly, and transitioning to other states based on playback events.

In the overall FSM playback module, `AdPlayingState` handles the scenario when an ad is actively playing, ensuring seamless integration of ads into the user experience by managing player instances, resume positions, and UI visibility.


Class: AdPlayingState

Inheritance


Purpose


Key Methods

1. transformToState(Input input, StateFactory factory) : State

**Description:** Determines the next state of the FSM based on an input event received during ad playback.

**Parameters:**

**Returns:**

**Behavior:**

**Example Usage:**

State nextState = adPlayingState.transformToState(Input.AD_FINISH, stateFactory);
// nextState will be an instance of MoviePlayingState

2. performWorkAndUpdatePlayerUI(@NonNull FsmPlayer fsmPlayer) : void

**Description:** Executes the core work associated with this state and updates the player UI accordingly.

**Parameters:**

**Behavior:**


3. playingAdAndPauseMovie(PlayerUIController controller, AdMediaModel adMediaModel, PlayerAdLogicController componentController, FsmPlayer fsmPlayer) : void

**Description:** Internal helper method responsible for setting up the ad player, pausing the main content player, configuring UI components, and starting ad playback.

**Parameters:**

**Behavior:**

**Important Details:**


4. hideVpaidNShowPlayer(final PlayerUIController imcontroller) : void

**Description:** Ensures that the standard video player UI is visible and the VPAID WebView is hidden and cleared.

**Parameters:**

**Behavior:**


Important Implementation Details


Interaction with Other System Components


Usage Example

This state is typically not instantiated directly by client code but managed internally by the FSM player during playback:

// Sample FSM transition triggering ad playback
fsmPlayer.transit(Input.AD_RECEIVED); // This could cause transition to AdPlayingState

// Inside AdPlayingState.performWorkAndUpdatePlayerUI():
// Sets up the ad player, pauses the movie player, and starts playing the ad

// On ad finish event:
fsmPlayer.transit(Input.AD_FINISH); // Transitions to MoviePlayingState to resume content playback

Mermaid Class Diagram

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

    class BaseState {
        +transformToState(input: Input, factory: StateFactory): State
        +performWorkAndUpdatePlayerUI(fsmPlayer: FsmPlayer): void
    }

    class Input {
        <<enumeration>>
        +NEXT_AD
        +AD_CLICK
        +AD_FINISH
        +VPAID_MANIFEST
        //... other inputs
    }

    class StateFactory {
        +createState(classType: Class): State
    }

    class FsmPlayer {
        +transit(input: Input): void
        +getPlayerUIController(): PlayerUIController
        +getPlayerAdLogicController(): PlayerAdLogicController
        // Other methods
    }

    AdPlayingState --> Input
    AdPlayingState --> StateFactory
    AdPlayingState --> FsmPlayer

Summary

This class is a core part of the FSM's ad management capabilities, enabling a modular and maintainable approach to handling advertisement playback in the media player.


End of Documentation for AdPlayingState.java