MoviePlayingState.java


Overview

`MoviePlayingState.java` defines the **MoviePlayingState** class, a concrete state within the media player's Finite State Machine (FSM). This state represents the playback of the main movie content after advertisements have finished playing. Its primary function is to manage and coordinate the transition from ad playback back to content playback, ensuring a seamless viewing experience. It handles preparation of the movie player, resuming playback positions, subtitle visibility, and UI updates related to hiding ad components.

This class extends `BaseState` and overrides key methods to implement the behavior specific to playing movie content, including responding to inputs that trigger transitions to other states like making an ad call or finishing playback.


Class: MoviePlayingState

Inheritance


Purpose


Public Methods

State transformToState(Input input, StateFactory factory)

Determines the next FSM state based on the input event.


void performWorkAndUpdatePlayerUI(@NonNull FsmPlayer fsmPlayer)

Executes the work associated with this state and updates the player UI accordingly.


Private Methods

void stopAdandPlayerMovie(PlayerUIController controller, PlayerAdLogicController componentController, MediaModel movieMedia)

Stops ad playback and prepares the movie player for playback.


void updatePlayerPosition(SimpleExoPlayer moviePlayer, PlayerUIController controller)

Updates the movie player's playback position based on history or resume position.


void hideVpaidNShowPlayer(final PlayerUIController controller)

Hides the VPAID WebView and shows the movie player view.


boolean shouldShowSubtitle()

Determines whether subtitles should be visible in the current playback context.


Important Implementation Details


Usage Example

// Assuming fsmPlayer is an initialized FSM player object
MoviePlayingState moviePlayingState = new MoviePlayingState();
StateFactory factory = new StateFactory();

// Perform movie playback setup and UI updates
moviePlayingState.performWorkAndUpdatePlayerUI(fsmPlayer);

// Transition to making ad call state if triggered
State nextState = moviePlayingState.transformToState(Input.MAKE_AD_CALL, factory);
if (nextState != null) {
    fsmPlayer.setCurrentState(nextState);
    nextState.performWorkAndUpdatePlayerUI(fsmPlayer);
}

Interaction with Other System Components


Mermaid Class Diagram

classDiagram
    class MoviePlayingState {
        +State transformToState(Input input, StateFactory factory)
        +void performWorkAndUpdatePlayerUI(FsmPlayer fsmPlayer)
        -void stopAdandPlayerMovie(PlayerUIController, PlayerAdLogicController, MediaModel)
        -void updatePlayerPosition(SimpleExoPlayer, PlayerUIController)
        -void hideVpaidNShowPlayer(PlayerUIController)
        -boolean shouldShowSubtitle()
    }
    MoviePlayingState --|> BaseState

Summary

`MoviePlayingState` plays a critical role in the FSM playback system by managing the content playback phase. It ensures smooth transitions from ads back to movie playback, handles player preparation and resume logic, and updates UI components responsibly. Its design encapsulates the specifics of movie playback within the broader FSM, facilitating modular, maintainable, and testable playback state management.


End of MoviePlayingState.java Documentation