FsmPlayerImperial.java


Overview

`FsmPlayerImperial.java` is an abstract class extending the core finite state machine (FSM) player `FsmPlayer`. It implements the `CuePointCallBack` interface to handle cue point events specifically related to ad insertion points during media playback. This class adds logic to detect preroll ads (cue points at time zero) and update the cue point monitor accordingly. It also manages state transitions triggered by the presence or absence of preroll ads and handles cue point fetch errors by transitioning to error states.

In essence, `FsmPlayerImperial` bridges the asynchronous cue point retrieval process with the FSM's playback state transitions, ensuring preroll ads are properly recognized and managed within the FSM playback lifecycle.


Detailed Explanation

Class: FsmPlayerImperial

public abstract class FsmPlayerImperial extends FsmPlayer implements CuePointCallBack

Description

Constructor

public FsmPlayerImperial(StateFactory factory)

Methods

onCuePointReceived(long[] cuePoints)

@Override
public void onCuePointReceived(long[] cuePoints)
// Assuming cue points fetched as [0, 30000, 60000]
long[] cuePoints = {0L, 30000L, 60000L};
fsmPlayerImperialInstance.onCuePointReceived(cuePoints);
// FSM transitions to handle preroll ad and updates cue point monitor accordingly.

onCuePointError()

@Override
public void onCuePointError()

updateCuePointsWithRemoveFirstCue(long[] array, boolean yes)

private void updateCuePointsWithRemoveFirstCue(long[] array, boolean yes)

hasPrerollAd(long[] cuePoints)

private boolean hasPrerollAd(long[] cuePoints)

removePreroll(long[] array)

private long[] removePreroll(long[] array)

Important Implementation Details


Interaction with Other System Components


Usage Example

StateFactory factory = new StateFactory();
FsmPlayerImperial player = new FsmPlayerImperial(factory) {
    // Implement abstract methods if any
};

// Cue points fetched asynchronously:
long[] cuePoints = {0L, 45000L, 90000L};
player.onCuePointReceived(cuePoints);

// The FSM will detect preroll, remove the 0 cue point from monitor,
// transition to the preroll ad handling state,
// and notify the UI component.

Mermaid Class Diagram

classDiagram
    class FsmPlayerImperial {
        -static final String TAG
        +FsmPlayerImperial(StateFactory factory)
        +void onCuePointReceived(long[] cuePoints)
        +void onCuePointError()
        -void updateCuePointsWithRemoveFirstCue(long[] array, boolean yes)
        -boolean hasPrerollAd(long[] cuePoints)
        -long[] removePreroll(long[] array)
    }
    FsmPlayerImperial --|> FsmPlayer
    FsmPlayerImperial ..|> CuePointCallBack

Summary

`FsmPlayerImperial.java` is a specialized extension of the FSM player that handles cue point callbacks in the media playback FSM. It detects preroll ads (cue point at 0), updates the cue point list to exclude preroll from midroll monitoring, and triggers state transitions accordingly. It also handles cue point fetch errors by transitioning to an error state. This class plays a critical role in integrating asynchronous cue point retrieval with the FSM playback logic, enabling correct ad playback scheduling and UI updates within the Tubitv media player system.