Dependency Injection Integration
Purpose
This integration addresses the challenge of managing complex dependencies among the finite state machine (FSM) player, playback controllers, ad interfaces, and UI components within the dual-player media system. By employing Dagger 2 dependency injection, it ensures that these components are created, configured, and scoped consistently, promoting modularity, ease of testing, and cleaner separation of concerns within the player activity.
Functionality
The dependency injection setup provides scoped instances of critical playback components, wiring them together automatically and injecting them into the player activity. Key workflows include:
Component and Module Definition
The Dagger componentFsmComonentRealdeclares injection targets (e.g., theRealActivity) and binds to the moduleFSMModuleRealwhich provides concrete instances.Provision of Playback and Ad Controllers
The module creates and suppliesFsmPlayerImperial(the FSM player),PlayerUIController, andPlayerAdLogicControllerinstances. These controllers manage content and ad playback logic and UI coordination.Ad and Cue Point Data Providers
Fake or real implementations for fetching ads (AdInterface) and cue points (CuePointCallBack) are provided asynchronously to simulate or handle network retrieval.Scoped Lifecycle Management
Components are annotated with a custom @ActicityScope to limit their lifecycle to that of the activity, avoiding memory leaks and unnecessary recreations.Injection Invocation
The player activity (RealActivity) triggers injection in its lifecycle via the Dagger-generated builder, passing required parameters such as the VPAID WebView and root view.
Example Injection Snippet
@Override
protected void injectDependency() {
DaggerFsmComonentReal.builder()
.fSMModuleReal(new FSMModuleReal(vpaidWebView, mTubiPlayerView))
.build()
.inject(this);
}
This call creates the Dagger graph, linking the player UI and ad controllers, FSM player, monitors, and ad interfaces for use within the activity.
Integration
Dependency Injection Integration tightly couples with the **Dual Player Activity** by supplying all necessary components the activity requires for orchestrating playback and ad logic. It abstracts away manual instantiation and configuration, thereby complementing:
Dual Player Setup: By injecting the FSM player and controllers, it facilitates management of the two ExoPlayer instances for content and ads.
Ad and Cue Point Management: Injected
AdInterfaceand retrievers enable the FSM to asynchronously fetch and manage ad content and cue points without hardcoding dependencies.VPAID Ad Integration: The
VpaidClient(e.g.,TubiVPAID) is injected with the WebView and FSM player references for handling interactive ads.
This subtopic introduces the modular injection pattern, which is not covered in other dual player subtopics, providing a clean mechanism to manage component lifecycles and dependencies effectively.
Diagram
flowchart TD
Activity[RealActivity]
FSMModule[FSMModuleReal]
Component[DaggerFsmComonentReal]
FSMPlayer[FsmPlayerImperial]
UIController[PlayerUIController]
AdController[PlayerAdLogicController]
AdRetriever[AdRetriever]
CuePointRetriever[CuePointsRetriever]
AdInterface[AdInterface Implementation]
VpaidClient[TubiVPAID]
WebView[WebView Instance]
RootView[Player Root View]
Activity -->|calls inject()| Component
Component -->|provides| FSMPlayer
Component -->|provides| UIController
Component -->|provides| AdController
Component -->|provides| AdRetriever
Component -->|provides| CuePointRetriever
Component -->|provides| AdInterface
Component -->|provides| VpaidClient
FSMModule -->|constructs| FSMPlayer
FSMModule -->|constructs| UIController
FSMModule -->|constructs| AdController
FSMModule -->|constructs| AdRetriever
FSMModule -->|constructs| CuePointRetriever
FSMModule -->|constructs| AdInterface
FSMModule -->|constructs| VpaidClient
FSMModule --> WebView
FSMModule --> RootView
This diagram visualizes how the `RealActivity` depends on the Dagger component to inject all necessary playback and ad-related components, which are constructed and provided by the `FSMModuleReal` using the WebView and root view as contextual parameters.