RealActivity.java
Overview
`RealActivity` is a concrete implementation of a dual-player video playback activity within the Tubitv media demo app. It extends `DoubleViewTubiPlayerActivity`, a base class designed to manage two ExoPlayer instances simultaneously—one for content playback and another for advertisement playback. `RealActivity` customizes dependency injection by supplying real implementations of the finite state machine (FSM) playback components and provides a user interaction interface overlay for controlling playback.
Specifically, `RealActivity`:
Injects real FSM-related components via Dagger 2 dependency injection.
Overrides the UI container for user interaction to provide a custom player controller interface.
Relies on the dual-player architecture and FSM logic defined in its superclass to orchestrate content and ad playback.
This class acts as the entry point for a real-world playback scenario using all live components rather than mocks or stubs.
Class Details
Class: RealActivity
**Package:** `com.tubitv.media.demo`
**Superclass:** `DoubleViewTubiPlayerActivity`
Methods
protected void injectDependency()
Overrides the base class method to inject dependencies specific to the "real" FSM playback module.
Purpose:
Initializes the Dagger dependency injection graph with real implementations instead of defaults or mocks. This includes FSM player logic, UI controllers, ad retrievers, and VPAID WebView handlers.Implementation Details:
Uses the generatedDaggerFsmComonentRealbuilder to create the component graph, passing an instance ofFSMModuleRealconstructed with references to the VPAID WebView and the main player view (mTubiPlayerView). Then calls.inject(this)to perform field injection on the activity.Parameters:
NoneReturns:
NoneUsage Example:
@Override protected void injectDependency() { DaggerFsmComonentReal.builder() .fSMModuleReal(new FSMModuleReal(vpaidWebView, mTubiPlayerView)) .build() .inject(this); }
public View addUserInteractionView()
Overrides the method to provide a custom UI controller view layered on top of the video player.
Purpose:
Adds a user interaction view that allows users to control playback (play, pause, seek, etc.) through a custom UI component.Implementation Details:
InstantiatesPlayerControllerUI, a custom UI component for player controls, passing the base context. Sets the controller interface with the player controller obtained from the superclass (getPlayerController()), cast toUserController.Parameters:
NoneReturns:
View— the UI component to be embedded in the activity's view hierarchy, representing playback controls.
Usage Example:
@Override public View addUserInteractionView() { return new PlayerControllerUI(getBaseContext()) .setController((UserController) getPlayerController()); }
Important Implementation Details
Dependency Injection:
RealActivityleverages a Dagger 2 component namedDaggerFsmComonentRealand a moduleFSMModuleReal. These components provide real implementations of the FSM player and its auxiliary classes, fully wiring the playback logic, ad handling, and UI controls.Dual Player Architecture:
Inherited fromDoubleViewTubiPlayerActivity,RealActivityoperates two ExoPlayer instances: one for content and one for ads. The FSM player manages state transitions between these two players.Custom UI Controller:
The user interaction view returned byaddUserInteractionView()is aPlayerControllerUIinstance, which provides playback controls linked to the underlying playback FSM and ExoPlayer instances.Minimal Override:
This class serves primarily to configure dependency injection and UI layering. The main playback logic, lifecycle handling, and event management occur in the superclass and injected components.
Interaction with Other System Components
Superclass (
DoubleViewTubiPlayerActivity):
Provides the core dual-player playback mechanism, including player initialization, playback state management, UI binding, and lifecycle handling.Dagger Components and Modules:
DaggerFsmComonentReal— The Dagger component responsible for injecting the FSM player and related classes into this activity.FSMModuleReal— Supplies concrete implementations of FSM players, UI controllers, ad retrievers, and the VPAID WebView client.
UI Components:
PlayerControllerUI— Provides the user controls UI overlay linked to the player controller interface.UserController— Interface for controlling playback, implemented by the FSM player or controller classes.
Playback and Ad System:
FSM player orchestrates playback of content and ads, switching between the two ExoPlayers.
WebView handles VPAID ads rendered alongside the player views.
Usage Example
// In manifest or app flow, RealActivity is launched to start a playback session with real FSM components.
Intent intent = new Intent(context, RealActivity.class);
context.startActivity(intent);
Once launched, `RealActivity` sets up the dual player environment with real playback and ad logic, injects dependencies, and adds the user interaction controls on top of the video.
Mermaid Class Diagram
classDiagram
class RealActivity {
+void injectDependency()
+View addUserInteractionView()
}
RealActivity --|> DoubleViewTubiPlayerActivity
class DoubleViewTubiPlayerActivity {
<<abstract>>
+void injectDependency()
+View addUserInteractionView()
+UserController getPlayerController()
-- ExoPlayer mMoviePlayer
-- ExoPlayer adPlayer
-- WebView vpaidWebView
-- View mTubiPlayerView
}
class PlayerControllerUI {
+PlayerControllerUI(Context context)
+PlayerControllerUI setController(UserController controller)
}
RealActivity ..> PlayerControllerUI : uses
RealActivity ..> DaggerFsmComonentReal : uses
RealActivity ..> FSMModuleReal : uses
Summary
`RealActivity` is a thin but crucial subclass that configures the dual ExoPlayer-based video playback activity to use real FSM playback components with full dependency injection and provides a custom user control interface. It acts as the concrete playback activity in the Tubitv app demo, enabling rich video and ad playback experiences with modular and testable architecture. The actual playback lifecycle, FSM logic, and ad management are delegated to its superclass and injected classes.
References
DoubleViewTubiPlayerActivity— Base class managing dual ExoPlayer instances and playback FSM.PlayerControllerUI— UI component providing playback controls.DaggerFsmComonentReal&FSMModuleReal— Dagger 2 DI setup supplying real FSM player implementations.VPAID WebView — Used for rendering interactive ads alongside the video player views.