DoublePlayerInterface.java


Overview

`DoublePlayerInterface` defines a contract for managing two layered ExoPlayer instances within an Android media playback context. Specifically, it handles one player for displaying main video content and another player dedicated to showing video advertisements. This interface encapsulates the strategy for preparing ad media and managing player states to enable seamless ad insertion without interrupting the main content playback flow.

By abstracting these operations, `DoublePlayerInterface` allows different implementations to manage the lifecycle and interactions between the two players, supporting use cases such as preloading ads, switching media sources, and coordinating playback states.


Interface Details

DoublePlayerInterface


Methods

1. void onPrepareAds(AdMediaModel ads)

Prepares an advertisement media model by injecting or associating a `MediaSource` that the player can use for playback.


2. void prepareFSM()

Prepares the finite state machine (FSM) or player state management logic.


Important Implementation Details


Interaction with Other Components


Mermaid Class Diagram

classDiagram
    class DoublePlayerInterface {
        <<interface>>
        +void onPrepareAds(AdMediaModel ads)
        +void prepareFSM()
    }
    class AdMediaModel {
        +String adUrl
        +MediaSource mediaSource
        +void setMediaSource(MediaSource mediaSource)
        +MediaSource getMediaSource()
    }
    DoublePlayerInterface ..> AdMediaModel : uses

Summary

`DoublePlayerInterface` is a concise interface defining essential methods to prepare video advertisements and manage playback states using two ExoPlayer instances — one for main content and one for ads. It facilitates seamless ad insertion and playback management in media applications, abstracting critical functionalities for preparing ad media sources and initializing player state logic.

Implementers of this interface will provide the logic to handle media source creation, player synchronization, and state transitions, ensuring a smooth viewing experience that integrates ads without disrupting the main video content.