CuePointMonitor.java


Overview

`CuePointMonitor` is an abstract class designed to monitor video playback progress on a frame-by-frame basis and coordinate advertisement-related actions within a media player leveraging ExoPlayer. It integrates tightly with a finite state machine player (`FsmPlayer`) to manage ad retrieval and ad display based on predefined cue points in video content.

The primary responsibilities of this class are:

`CuePointMonitor` acts as a bridge between playback progress and the FSM controlling ad insertion, ensuring ads are requested and played at correct times without disrupting the user experience.


Class: CuePointMonitor

Package

package com.tubitv.media.fsm.listener;

Dependencies


Fields

Field

Type

Description

`TAG`

String

Class tag for logging purposes.

`RANGE_FACTOR`

long

Tolerance window (1.5 seconds) for approximate cue point matching in binary searches.

`fsmPlayer`

FsmPlayer

Reference to the FSM player instance for state transitions and cue point updates.

`safeCheckForAdcall`

boolean

Flag to ensure ad call network requests are triggered only once per cue point.

`safeCheckForCue`

boolean

Flag to ensure ad display triggers only once per cue point.

`cuePoints`

long[]

Array of cue point timestamps (in milliseconds) indicating when ads should play.

`adCallPoints`

long[]

Array of timestamps (milliseconds) for triggering ad network calls, offset ahead of cue points.

`currentQueuePointPos`

int

Index of the current active cue point being processed, or -1 if none.


Constructor

public CuePointMonitor(FsmPlayer fsmPlayer)

Public Methods

1. binarySerchWithRange(long[] a, long key) : int

2. binarySerchExactly(long[] a, long key) : int

3. abstract int networkingAhead()

4. void setQuePoints(@Nullable long[] cuePoints)

long[] cuePoints = {30000, 60000, 90000}; // at 30s, 60s, 90s
cuePointMonitor.setQuePoints(cuePoints);

5. void onMovieProgress(long milliseconds, long durationMillis)

cuePointMonitor.onMovieProgress(currentPositionMs, totalDurationMs);

Protected / Private Methods

1. void preformAdCallIfNecessary(long milliseconds)

2. void preformShowAdIfNecessary(long milliseconds)

3. boolean isProgressActionable(long[] array, long currentProgress)

4. long[] getAddCallPoints(long[] cuePoints)

5. void remoteShowedCuePoints()

6. long[] removeElementFromArray(long[] array, int keyPos)


Important Implementation Details


Interaction with Other Components


Usage Example

// Subclass defines networkingAhead()
public class MyCuePointMonitor extends CuePointMonitor {
    @Override
    public int networkingAhead() {
        return 5000; // 5 seconds before cue point
    }
}

// Usage
FsmPlayer fsmPlayer = ...; // initialized FSM player instance
MyCuePointMonitor monitor = new MyCuePointMonitor(fsmPlayer);

// Set cue points in milliseconds
long[] cuePoints = {30000, 60000, 90000}; // 30s, 60s, 90s
monitor.setQuePoints(cuePoints);

// During playback, call onMovieProgress continuously
long currentPosition = 29500; // e.g., 29.5 seconds
monitor.onMovieProgress(currentPosition, 120000); // total duration 2 minutes

Visual Diagram

classDiagram
    class CuePointMonitor {
        -static final String TAG
        -static final long RANGE_FACTOR
        -FsmPlayer fsmPlayer
        -boolean safeCheckForAdcall
        -boolean safeCheckForCue
        -long[] cuePoints
        -long[] adCallPoints
        -int currentQueuePointPos
        +CuePointMonitor(FsmPlayer fsmPlayer)
        +static int binarySerchWithRange(long[] a, long key)
        +static int binarySerchExactly(long[] a, long key)
        #abstract int networkingAhead()
        +void setQuePoints(long[] cuePoints)
        +void onMovieProgress(long milliseconds, long durationMillis)
        -void preformAdCallIfNecessary(long milliseconds)
        -void preformShowAdIfNecessary(long milliseconds)
        -boolean isProgressActionable(long[] array, long currentProgress)
        -long[] getAddCallPoints(long[] cuePoints)
        +void remoteShowedCuePoints()
        -long[] removeElementFromArray(long[] array, int keyPos)
    }

Summary

`CuePointMonitor` is a crucial component for ad insertion in media playback, providing a robust mechanism to detect playback proximity to cue points and coordinate with a finite state machine to fetch and show ads timely. Its design ensures efficiency through binary search with tolerance, safety through trigger flags, and flexibility via an abstract networking ahead parameter. It maintains clear separation of concerns by delegating playback and UI control to other system components while focusing on cue point monitoring logic.


End of Documentation for CuePointMonitor.java