PlayerModuleDefault.java


Overview

`PlayerModuleDefault.java` is a **Dagger 2 module** responsible for providing default, scoped dependencies related to the media player system within the Tubitv media framework. It defines how core playback components, such as the **finite state machine (FSM) player**, UI controllers, ad retrieval mechanisms, playback monitors, and VPAID clients, are instantiated and injected into the application.

This module is designed for **default or demo environments**, supplying mostly stub or no-op implementations that enable the player system to function without requiring live networking or complex UI integrations like WebView. It serves as a simple, self-contained provider for essential playback services scoped to an activity lifecycle, supporting modularity, testability, and lifecycle management.


Classes and Methods

Class: PlayerModuleDefault

A Dagger module annotated with `@Module` that provides scoped instances of player-related components.

Constructor

public PlayerModuleDefault()

Provided Dependencies (Methods)

Each method is annotated with `@Provides` and `@ActicityScope` (a custom scope controlling lifecycle within an activity). These methods define how a particular dependency is created.


1. provideStateFactory()

@ActicityScope
@Provides
StateFactory provideStateFactory()

**Example:**

StateFactory factory = playerModuleDefault.provideStateFactory();

2. provideFsmPlayer(StateFactory factory)

@ActicityScope
@Provides
FsmPlayer provideFsmPlayer(StateFactory factory)

**Example:**

FsmPlayer player = new FsmPlayerImperial(factory) {
    @Override
    public Class initializeState() {
        return FetchCuePointState.class;
    }
};

3. provideController()

@ActicityScope
@Provides
PlayerUIController provideController()

4. provideComponentController()

@ActicityScope
@Provides
PlayerAdLogicController provideComponentController()

5. provideAdRetriever()

@ActicityScope
@Provides
AdRetriever provideAdRetriever()

6. provideCuePointsRetriever()

@ActicityScope
@Provides
CuePointsRetriever provideCuePointsRetriever()

7. provideAdPlayingMonitor(FsmPlayer player)

@ActicityScope
@Provides
AdPlayingMonitor provideAdPlayingMonitor(FsmPlayer player)

8. provideCuePointMonitor(FsmPlayer fsmPlayer)

@ActicityScope
@Provides
CuePointMonitor provideCuePointMonitor(FsmPlayer fsmPlayer)

9. provideAdMediaModel()

@ActicityScope
@Provides
AdMediaModel provideAdMediaModel()

10. provideAdInterfaceNoPreroll()

@ActicityScope
@Provides
AdInterface provideAdInterfaceNoPreroll()

11. provideVpaidClient()

@ActicityScope
@Provides
VpaidClient provideVpaidClient()

Important Implementation Details


Interaction with Other Parts of the System


Usage Example

Assuming a Dagger component includes `PlayerModuleDefault`:

@Component(modules = PlayerModuleDefault.class)
@ActicityScope
public interface PlayerComponent {
    void inject(MyPlayerActivity activity);
}

In an injected activity:

@Inject
FsmPlayer fsmPlayer;

@Inject
PlayerUIController uiController;

@Inject
AdInterface adInterface;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    playerComponent.inject(this);

    // FSM player starts in FetchCuePointState
    fsmPlayer.start();

    // Use adInterface to fetch ads (returns stub immediately)
    adInterface.fetchAd(new AdRetriever(), new RetrieveAdCallback() {
        @Override
        public void onReceiveAd(AdMediaModel adMedia) {
            // Handle received ad media
        }
    });
}

Mermaid Class Diagram

classDiagram
    class PlayerModuleDefault {
        +PlayerModuleDefault()
        +provideStateFactory() StateFactory
        +provideFsmPlayer(factory: StateFactory) FsmPlayer
        +provideController() PlayerUIController
        +provideComponentController() PlayerAdLogicController
        +provideAdRetriever() AdRetriever
        +provideCuePointsRetriever() CuePointsRetriever
        +provideAdPlayingMonitor(player: FsmPlayer) AdPlayingMonitor
        +provideCuePointMonitor(fsmPlayer: FsmPlayer) CuePointMonitor
        +provideAdMediaModel() AdMediaModel
        +provideAdInterfaceNoPreroll() AdInterface
        +provideVpaidClient() VpaidClient
    }

Summary

`PlayerModuleDefault.java` is a fundamental Dagger module in the Tubitv media player framework responsible for:

This module plays a vital role in the modular architecture of the media playback system, allowing different runtime configurations and easing testing and development efforts.


End of Documentation for PlayerModuleDefault.java