PlayerAdLogicController.java
Overview
`PlayerAdLogicController` is a controller class within the `com.tubitv.media.controller` package designed to manage and coordinate the interactions and logic related to advertisement playback in the media player system of the Tubitv platform. This class acts as a centralized holder and manager for various interfaces and listeners that monitor and control ad playback, cue points, and VPAID (Video Player-Ad Interface Definition) client interactions.
Rather than implementing ad playback logic directly, this controller aggregates several key components related to ad playback logic and exposes getter and setter methods to manipulate these components. This design facilitates decoupling between the ad playback logic and the underlying player and monitoring implementations, enabling flexible integration and testing.
Classes, Methods, and Usage
Class: PlayerAdLogicController
This is the sole class in the file.
Properties (Private Members)
Property | Type | Description |
|---|---|---|
`adPlayingMonitor` | `AdPlayingMonitor` | Listener interface that monitors the current state of ad playback. |
`playbackActionCallback` | `PlaybackActionCallback` | Callback interface for playback actions related to ads and media. |
`doublePlayerInterface` | `DoublePlayerInterface` | Interface managing two players (possibly separating content and ads). |
`cuePointMonitor` | `CuePointMonitor` | Listener for cue points in media playback, typically for triggering ads or other events. |
`vpaidClient` | `VpaidClient` | Client interface for handling VPAID ads, allowing interaction with VPAID-compliant ad units. |
Constructors
Default Constructor
public PlayerAdLogicController()Initializes an empty controller with all properties set to
null.Usage:
PlayerAdLogicController controller = new PlayerAdLogicController();
Constructor without VpaidClient
public PlayerAdLogicController(@Nullable AdPlayingMonitor adPlayingMonitor, @Nullable PlaybackActionCallback playbackActionCallback, @Nullable DoublePlayerInterface doublePlayerInterface, @Nullable CuePointMonitor cuePointMonitor)Initializes the controller with the provided listeners and interfaces except for
vpaidClient.Parameters can be
nullif not available.Usage:
PlayerAdLogicController controller = new PlayerAdLogicController(adMonitor, playbackCallback, doublePlayer, cuePointMonitor);
Constructor with VpaidClient
public PlayerAdLogicController(@Nullable AdPlayingMonitor adPlayingMonitor, @Nullable PlaybackActionCallback playbackActionCallback, @Nullable DoublePlayerInterface doublePlayerInterface, @Nullable CuePointMonitor cuePointMonitor, @Nullable VpaidClient vpaidClient)Initializes the controller with all provided components, including the VPAID client.
Usage:
PlayerAdLogicController controller = new PlayerAdLogicController(adMonitor, playbackCallback, doublePlayer, cuePointMonitor, vpaidClient);
Getters and Setters
Each component has a corresponding getter and setter allowing retrieval and modification:
Ad Playing Monitor
public AdPlayingMonitor getAdPlayingMonitor() public void setAdPlayingMonitor(AdPlayingMonitor adPlayingMonitor)Playback Action Callback
public PlaybackActionCallback getTubiPlaybackInterface() public void setTubiPlaybackInterface(PlaybackActionCallback playbackActionCallback)Double Player Interface
public DoublePlayerInterface getDoublePlayerInterface() public void setDoublePlayerInterface(DoublePlayerInterface doublePlayerInterface)Cue Point Monitor
public CuePointMonitor getCuePointMonitor() public void setCuePointMonitor(CuePointMonitor cuePointMonitor)VPAID Client
@Nullable public VpaidClient getVpaidClient() public void setVpaidClient(@Nullable VpaidClient vpaidClient)
Important Implementation Details
Nullability: Multiple constructors and setters accept nullable parameters, indicating components are optional and may be set or replaced dynamically during runtime.
No Business Logic Inside: The class acts purely as a holder and accessor for ad playback-related interfaces and listeners. Actual ad playback control, event handling, and media control are expected to be handled by the injected components.
VPAID Support: Inclusion of
VpaidClientindicates support for VPAID ads, which allow rich interactive ads with bidirectional communication between the player and the ad.Modularity and Decoupling: By abstracting the interfaces and monitors behind this controller, the system supports flexibility in swapping or mocking components for testing or feature extensions.
Interaction with Other System Components
AdPlayingMonitor: Likely monitors ad playback states such as start, pause, complete, or error events.
PlaybackActionCallback: Provides hooks to control or receive notifications about playback actions, possibly for synchronizing UI or media state.
DoublePlayerInterface: Manages two media players simultaneously, probably separating main content playback and ad playback.
CuePointMonitor: Tracks cue points within the media timeline, triggering ad playback or other actions at specified times.
VpaidClient: Interfaces with VPAID ads, facilitating communication and control over interactive ads.
This controller is central to the media player’s ad logic layer, enabling coordination between playback components, ad monitors, and VPAID clients.
Usage Example
// Instantiate monitors and interfaces (implementations omitted for brevity)
AdPlayingMonitor adMonitor = ...;
PlaybackActionCallback playbackCallback = ...;
DoublePlayerInterface doublePlayer = ...;
CuePointMonitor cuePointMonitor = ...;
VpaidClient vpaidClient = ...;
// Create controller with all components
PlayerAdLogicController adLogicController = new PlayerAdLogicController(
adMonitor,
playbackCallback,
doublePlayer,
cuePointMonitor,
vpaidClient
);
// Access and interact with components
adLogicController.getAdPlayingMonitor().onAdStarted();
adLogicController.getDoublePlayerInterface().playAd();
Mermaid Class Diagram
classDiagram
class PlayerAdLogicController {
- AdPlayingMonitor adPlayingMonitor
- PlaybackActionCallback playbackActionCallback
- DoublePlayerInterface doublePlayerInterface
- CuePointMonitor cuePointMonitor
- VpaidClient vpaidClient
+ PlayerAdLogicController()
+ PlayerAdLogicController(AdPlayingMonitor, PlaybackActionCallback, DoublePlayerInterface, CuePointMonitor)
+ PlayerAdLogicController(AdPlayingMonitor, PlaybackActionCallback, DoublePlayerInterface, CuePointMonitor, VpaidClient)
+ getAdPlayingMonitor() AdPlayingMonitor
+ setAdPlayingMonitor(AdPlayingMonitor)
+ getTubiPlaybackInterface() PlaybackActionCallback
+ setTubiPlaybackInterface(PlaybackActionCallback)
+ getDoublePlayerInterface() DoublePlayerInterface
+ setDoublePlayerInterface(DoublePlayerInterface)
+ getCuePointMonitor() CuePointMonitor
+ setCuePointMonitor(CuePointMonitor)
+ getVpaidClient() VpaidClient
+ setVpaidClient(VpaidClient)
}
Summary
`PlayerAdLogicController.java` provides a modular and flexible container for managing the different interfaces and listeners involved in ad playback within the Tubitv media player system. It simplifies the integration of ad playback monitoring, control, and VPAID client communication by serving as a centralized access point for these components. This design aids in maintaining a clean separation of concerns, enabling easier testing, maintenance, and future enhancements related to video advertisement playback logic.