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
Package:
com.tubitv.media.interfacesPurpose: To define operations required for managing dual ExoPlayer instances — one for main content and one for ads.
Created by: Allen Sun, 7/24/2017
Methods
1. void onPrepareAds(AdMediaModel ads)
Prepares an advertisement media model by injecting or associating a `MediaSource` that the player can use for playback.
Parameters:
ads(AdMediaModel): The ad media model instance which will be configured with a media source representing the ad content.
Return: None
Description:
This method is responsible for preparing the ad content before playback. Typically, this involves creating or assigning an ExoPlayerMediaSourceto theAdMediaModel. TheMediaSourceencapsulates the ad video stream, allowing the player to load and play it.Usage Example:
AdMediaModel adModel = new AdMediaModel("ad_url"); doublePlayerInterface.onPrepareAds(adModel); // After preparation, the adModel will contain the MediaSource ready for playback.Notes: Implementations should ensure that the
MediaSourceis correctly configured and ready to be inserted into the ad player instance.
2. void prepareFSM()
Prepares the finite state machine (FSM) or player state management logic.
Parameters: None
Return: None
Description:
This method likely initializes or resets the internal state machine controlling the playback states of the two ExoPlayers. Preparing the FSM ensures that the player states (e.g., idle, buffering, playing, paused) are correctly managed, especially when switching between main content and ads.Usage Example:
doublePlayerInterface.prepareFSM(); // FSM is now initialized to manage dual player state transitions.Notes: The actual FSM implementation details are abstracted by this interface. Implementations should set up necessary listeners, state variables, or transitions for smooth playback control.
Important Implementation Details
Two ExoPlayer Instances Strategy:
The interface supports a layered approach where two ExoPlayer instances operate simultaneously:
Main Player: Plays the primary video content.
Ad Player: Plays video advertisements on top of or instead of the main content.
MediaSource Injection:
The
onPrepareAdsmethod indicates thatAdMediaModelobjects are prepared by associating them with ExoPlayerMediaSourceobjects. This design enables dynamic ad insertion by swapping or layering media sources.State Management:
The
prepareFSMmethod suggests the use of a finite state machine to manage complex state transitions between the two players, ensuring smooth user experience without conflicts or playback glitches.
Interaction with Other Components
AdMediaModel(fromcom.tubitv.media.models):Represents the ad content metadata and playback configuration.
DoublePlayerInterfacedepends on this model to prepare ads.ExoPlayer (
com.google.android.exoplayer2):The underlying media playback engine used for both main content and ads. This interface abstracts how these players are managed and coordinated.
Potential Usage Context:
This interface is likely used by media playback controllers or managers within the app that handle video streaming with ad support, possibly integrated with the UI layer to switch views between main content and ads seamlessly.
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.