FSMModuleReal.java


Overview

`FSMModuleReal` is a Dagger 2 dependency injection module that provides concrete, scoped instances of key playback and ad-related components for the media player system. Designed for real-world use, it supports integration with Android UI elements such as `WebView` and root `View`, enabling advanced ad playback features including VPAID (Video Player Ad-Serving Interface Definition) ads.

This module wires together the finite state machine (FSM) player, playback controllers, ad retrievers, monitors, and a VPAID client, managing their lifecycles under a custom `@ActicityScope`. It simulates asynchronous network retrieval for ads and cue points, facilitating realistic demo or development environments without real ad servers.


Detailed Description

`FSMModuleReal` is responsible for providing instances of classes used throughout the media playback system by leveraging Dagger's `@Provides` methods. The provided dependencies are scoped to an activity lifecycle via the custom `@ActicityScope` annotation.

Key Responsibilities


Classes and Methods

Class: FSMModuleReal

**Package:** `com.tubitv.media.demo.di`

**Annotations:** `@Module`

**Fields:**

Field

Type

Description

`webView`

`WebView` (nullable)

Reference to the WebView used for VPAID ads.

`rootView`

`View` (nullable)

Root view of the player UI, used for UI control.

**Constructor:**

public FSMModuleReal(@Nullable WebView webView, @Nullable View rootView)

Provided Methods (Dagger @Provides annotated)

All methods are scoped with `@ActicityScope`, meaning their instances live as long as the activity lifecycle.


1. provideStateFactory

StateFactory provideStateFactory()

2. provideFsmPlayer

FsmPlayer provideFsmPlayer(StateFactory factory)
FsmPlayer player = provideFsmPlayer(stateFactory);
Class initialState = player.initializeState(); // returns FetchCuePointState.class

3. provideController

PlayerUIController provideController()

4. provideComponentController

PlayerAdLogicController provideComponentController()

5. provideAdRetriever

AdRetriever provideAdRetriever()

6. provideCuePointsRetriever

CuePointsRetriever provideCuePointsRetriever()

7. provideAdPlayingMonitor

AdPlayingMonitor provideAdPlayingMonitor(FsmPlayer player)

8. provideCuePointMonitor

CuePointMonitor provideCuePointMonitor(FsmPlayer fsmPlayer)

9. provideAdMediaModel

AdMediaModel provideAdMediaModel()

10. provideAdInterfaceNoPreroll

AdInterface provideAdInterfaceNoPreroll()
adInterface.fetchAd(adRetriever, new RetrieveAdCallback() {
    @Override
    public void onReceiveAd(AdMediaModel adMediaModel) {
        // Handle received ad media model
    }
});

11. provideVpaidClient

VpaidClient provideVpaidClient(FsmPlayer player)

Important Implementation Details


Interaction with Other System Components


Usage Example in Activity

// In an Android activity or fragment:

// Assume webView and rootView are initialized UI components
FSMModuleReal fsmModule = new FSMModuleReal(webView, rootView);

// Using a Dagger component that includes FSMModuleReal
FsmComonentReal component = DaggerFsmComonentReal.builder()
    .fSMModuleReal(fsmModule)
    .build();

component.inject(this);

// Injected fields include:
// - FsmPlayer player;
// - PlayerUIController uiController;
// - PlayerAdLogicController adController;
// - AdInterface adInterface;
// - VpaidClient vpaidClient;
// etc.

// The FSM player can then be started, and ads fetched asynchronously.

Visual Diagram: Class Structure of FSMModuleReal

classDiagram
    class FSMModuleReal {
        -WebView webView
        -View rootView
        +FSMModuleReal(webView, rootView)
        +provideStateFactory() StateFactory
        +provideFsmPlayer(StateFactory) FsmPlayer
        +provideController() PlayerUIController
        +provideComponentController() PlayerAdLogicController
        +provideAdRetriever() AdRetriever
        +provideCuePointsRetriever() CuePointsRetriever
        +provideAdPlayingMonitor(FsmPlayer) AdPlayingMonitor
        +provideCuePointMonitor(FsmPlayer) CuePointMonitor
        +provideAdMediaModel() AdMediaModel
        +provideAdInterfaceNoPreroll() AdInterface
        +provideVpaidClient(FsmPlayer) VpaidClient
    }

This diagram highlights the main class with its provided methods and injected UI components.


Summary

`FSMModuleReal` is a comprehensive Dagger 2 module that provides real, scoped instances of playback and ad-related components for a media player system with VPAID ad support. It integrates Android UI elements such as `WebView` and root player views, simulates asynchronous ad and cue point fetching, and supplies a concrete FSM player starting from cue point fetching. This module is a key part of the dependency injection setup, enabling modular, testable, and maintainable playback and ad logic integration in the player application.