MakingAdCallState.java


Overview

`MakingAdCallState` is a concrete implementation of a playback state within the Finite State Machine (FSM) architecture of the media player system. Its primary responsibility is to handle the process of fetching advertisements from the ad server during playback, typically for midroll or other non-preroll ads.

In this state, the player initiates an ad retrieval call asynchronously through the `AdInterface` and manages transitions based on input events such as the reception of ads or empty ad responses. Once an ad is received, the FSM transitions to the appropriate subsequent state to play the ad or handle the absence of ads.

This class extends `BaseState` and overrides key methods to implement its specific behavior in the playback lifecycle.


Class: MakingAdCallState

Package

com.tubitv.media.fsm.concrete

Inheritance

Purpose

Represents the "Making Ad Call" state in the FSM, responsible for:


Detailed Explanation

Methods


transformToState(Input input, StateFactory factory)

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

**Description:** Determines the next state based on the input event received while in the `MakingAdCallState`.

**Parameters:**

**Returns:**

**Behavior:**

**Usage Example:**

State nextState = makingAdCallState.transformToState(Input.AD_RECEIVED, stateFactory);

performWorkAndUpdatePlayerUI(@NonNull FsmPlayer fsmPlayer)

@Override
public void performWorkAndUpdatePlayerUI(@NonNull FsmPlayer fsmPlayer)

**Description:** Executes the main work of the state, which involves fetching the ad from the ad server via the `AdInterface`.

**Parameters:**

**Returns:** `void`

**Behavior:**

**Usage Example:**

makingAdCallState.performWorkAndUpdatePlayerUI(fsmPlayer);

fetchAd(AdInterface adInterface, AdRetriever retriever, RetrieveAdCallback callback)

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

**Description:** Helper method to initiate the ad retrieval process.

**Parameters:**

**Returns:** `void`

**Behavior:**

**Usage:**

This method is invoked internally by `performWorkAndUpdatePlayerUI`.


Important Implementation Details


Interaction with Other Components

FSM Player (FsmPlayer)

State Factory (StateFactory)

Other States

Ad Interfaces


Usage Example

FsmPlayer player = ...; // FsmPlayer instance properly initialized
StateFactory factory = new StateFactory();

MakingAdCallState makingAdCallState = factory.createState(MakingAdCallState.class);

// Perform work: fetch the ad asynchronously
makingAdCallState.performWorkAndUpdatePlayerUI(player);

// Later, upon receiving input event AD_RECEIVED from the ad fetch callback:
State nextState = makingAdCallState.transformToState(Input.AD_RECEIVED, factory);

// Transition to ReceiveAdState for ad preparation
player.setCurrentState(nextState);
nextState.performWorkAndUpdatePlayerUI(player);

Visual Diagram

classDiagram
    class MakingAdCallState {
        +transformToState(input: Input, factory: StateFactory): State
        +performWorkAndUpdatePlayerUI(fsmPlayer: FsmPlayer): void
        -fetchAd(adInterface: AdInterface, retriever: AdRetriever, callback: RetrieveAdCallback): void
    }
    MakingAdCallState --|> BaseState
    MakingAdCallState ..> AdInterface : uses
    MakingAdCallState ..> AdRetriever : uses
    MakingAdCallState ..> RetrieveAdCallback : implements
    MakingAdCallState ..> FsmPlayer : interacts with

    %% Transitions
    MakingAdCallState "1" --> "1" ReceiveAdState : on AD_RECEIVED
    MakingAdCallState "1" --> "1" AdPlayingState : on PRE_ROLL_AD_RECEIVED
    MakingAdCallState "1" --> "1" MakingAdCallState : on MAKE_AD_CALL

Summary

`MakingAdCallState` is a pivotal FSM state responsible for initiating asynchronous ad fetch calls to the ad server during playback. It waits for input events indicating the success or failure of ad retrieval and transitions accordingly. It does not update the UI directly but triggers the FSM to continue with appropriate ad playback or fallback states. Its design leverages dependency injection of interfaces and a factory pattern for state instantiation, promoting modularity and testability within the FSM playback framework.


References


See Also


End of Documentation for MakingAdCallState.java