FetchCuePointState.java


Overview

`FetchCuePointState` is a concrete state class within the Finite State Machine (FSM) playback system, specifically responsible for initiating the retrieval of cue points from the ad server. Cue points are timestamps within the media content that indicate when advertisements (such as preroll, midroll, or postroll ads) should be triggered.

This state plays a critical role in the ad integration workflow by:

If preroll ads are present, it transitions the FSM to `MakingPrerollAdCallState` for fetching preroll ads. Otherwise, it transitions directly to `MoviePlayingState` to start playing the main content.


Class: FetchCuePointState

Inheritance

Purpose

Encapsulates the behavior of fetching cue points from the ad server and deciding the next FSM state based on cue point data.


Methods

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

Determines the next state of the FSM based on the input event received.

Parameters

Returns

Usage Example

// Example of transitioning to next state based on input
State nextState = fetchCuePointState.transformToState(Input.HAS_PREROLL_AD, stateFactory);
// nextState is MakingPrerollAdCallState instance

void performWorkAndUpdatePlayerUI(@NonNull FsmPlayer fsmPlayer)

Executes the core action of this state, which is to fetch cue points from the ad server asynchronously. It performs no direct UI updates.

Parameters

Behavior

Usage Example

fetchCuePointState.performWorkAndUpdatePlayerUI(fsmPlayer);

private void fetchCuePointCall(AdInterface adInterface, CuePointsRetriever retriever, CuePointCallBack callBack)

Helper method that triggers the asynchronous fetching of cue points from the ad server.

Parameters

Behavior


Important Implementation Details


Interaction With Other Components


Usage Workflow

  1. The FSM enters FetchCuePointState when it needs to retrieve cue points.

  2. performWorkAndUpdatePlayerUI triggers the asynchronous cue point fetch.

  3. Upon receiving cue points, FsmPlayerImperial calls transit with either HAS_PREROLL_AD or NO_PREROLL_AD.

  4. transformToState returns the next appropriate state.

  5. FSM transitions to the preroll ad fetching state or directly to movie playback.


Mermaid Class Diagram

classDiagram
    class FetchCuePointState {
        +State transformToState(Input input, StateFactory factory)
        +void performWorkAndUpdatePlayerUI(FsmPlayer fsmPlayer)
        -void fetchCuePointCall(AdInterface adInterface, CuePointsRetriever retriever, CuePointCallBack callBack)
    }
    FetchCuePointState --|> BaseState

Summary

`FetchCuePointState` is a critical FSM player state that initiates cue point retrieval to determine ad insertion timing. It acts as a gateway in the ad playback workflow, enabling smooth transitions to preroll ad loading or content playback based on server-provided cue points. Its design emphasizes asynchronous operation, clear transition logic, and integration with the FSM player and ad server interfaces.


Example Usage in FSM Player (Simplified Pseudocode)

// Inside FsmPlayerImperial which implements CuePointCallBack
@Override
public void onCuePointReceived(long[] cuePoints) {
    if (cuePointsContainsPrerollAd(cuePoints)) {
        transit(Input.HAS_PREROLL_AD);
    } else {
        transit(Input.NO_PREROLL_AD);
    }
}

// The FSM Player transitions accordingly
fetchCuePointState.performWorkAndUpdatePlayerUI(fsmPlayer);
// Cue points will be fetched, and callback triggers next transition

References


End of Documentation for FetchCuePointState.java