MakingPrerollAdCallState.java


Overview

`MakingPrerollAdCallState` is a concrete state class within the Finite State Machine (FSM) playback system of the Tubitv media player. This state encapsulates the logic for initiating the retrieval of preroll advertisements before the main content playback begins.

In the FSM playback lifecycle, this state is responsible for:

This class extends the generic `BaseState` and overrides key methods to implement preroll-specific ad fetching behavior.


Class: MakingPrerollAdCallState

public class MakingPrerollAdCallState extends BaseState

Inheritance


Detailed Description

Purpose

This class represents the FSM state where the system makes a call to retrieve preroll ads. It prepares the necessary context (cue points) for the ad retriever and invokes the ad server interface to fetch ads asynchronously.

Key Responsibilities


Methods

1. transformToState

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

Description

Determines the next state based on the given input event. This method implements the FSM transition logic specific to preroll ad fetching.

Parameters

Returns

Behavior

Usage Example

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

2. performWorkAndUpdatePlayerUI

@Override
public void performWorkAndUpdatePlayerUI(@NonNull FsmPlayer fsmPlayer)

Description

Executes the preroll ad retrieval process and updates the player UI as necessary. This method is called when the FSM enters this state.

Parameters

Behavior

Usage Example

makingPrerollAdCallState.performWorkAndUpdatePlayerUI(fsmPlayer);

3. fetchAd

private void fetchAd(AdInterface adInterface, AdRetriever retriever, RetrieveAdCallback callback)

Description

Helper method to request ads from the ad server interface.

Parameters

Behavior

Logging


Implementation Details and Algorithms


Interactions with Other System Components


Usage Scenario Example

// Assuming fsmPlayer is the current FSM player instance and stateFactory is available

// Instantiate the preroll ad call state (normally done via factory)
MakingPrerollAdCallState prerollAdState = new MakingPrerollAdCallState();

// FSM enters preroll ad fetching state
fsmPlayer.setCurrentState(prerollAdState);

// FSM triggers the work to fetch preroll ads
prerollAdState.performWorkAndUpdatePlayerUI(fsmPlayer);

// Later, when ads are received:
State nextState = prerollAdState.transformToState(Input.PRE_ROLL_AD_RECEIVED, stateFactory);
if (nextState != null) {
    fsmPlayer.setCurrentState(nextState);
    // The player will now start playing the preroll ads
}

Visual Diagram: Class Structure of MakingPrerollAdCallState

classDiagram
    class MakingPrerollAdCallState {
        +State transformToState(Input input, StateFactory factory)
        +void performWorkAndUpdatePlayerUI(FsmPlayer fsmPlayer)
        -void fetchAd(AdInterface adInterface, AdRetriever retriever, RetrieveAdCallback callback)
    }
    MakingPrerollAdCallState --|> BaseState
    BaseState --|> State

Summary

`MakingPrerollAdCallState` is a pivotal FSM playback state responsible for initiating preroll ad retrieval. It updates the ad retriever's cue point contextually based on playback history, invokes the ad server interface to fetch ads asynchronously, and transitions to ad playback upon successful ad reception. This state ensures preroll ads are fetched and played seamlessly before the main content, contributing to a smooth and integrated user viewing experience.


If you need further details on related classes like `AdPlayingState`, `FsmPlayer`, or `StateFactory`, please refer to their respective documentation pages.