Project Overview

Project Purpose and Objectives

This project implements a modular, extensible media player system primarily targeting Android platforms. Its core purpose is to provide a robust video playback experience with advanced ad integration capabilities, including support for VPAID ads, cue points, and adaptive streaming. The system leverages a finite state machine (FSM) architecture to manage media playback states, including content playback, ad retrieval, and ad playing states, ensuring smooth transitions and consistent user experience.

The project objectives include:

Major Functionalities and Implementation Details

Example Workflows and Use Cases

Playback with Ads and FSM Transitions

  1. Initialization
    The player activity initializes the FSM player (FsmPlayerImperial) and injects dependencies using Dagger modules (FSMModuleReal or PlayerModuleDefault).

  2. Media Loading
    The content media (MediaModel) is loaded into the FSM player. The FSM starts in the FetchCuePointState to retrieve cue points from the ad server.

  3. Cue Points and Pre-roll Ads
    If preroll ads are present (detected via cue points), the FSM transitions to MakingPrerollAdCallState to fetch preroll ads.

  4. Ad Playback
    Ads are played within the AdPlayingState or VpaidState (for VPAID ads). Ad playback is managed on a dedicated ExoPlayer instance or via WebView for VPAID.

  5. Content Playback
    After ads, the FSM transitions to MoviePlayingState where the main content plays. Cue points are monitored to trigger midroll ads.

  6. User Interaction
    The UserController updates UI elements such as play/pause, seek bar, subtitles toggle, and ad-related UI components.

  7. Error Handling
    Playback errors or ad retrieval errors trigger FSM transitions to FinishState or error states, enabling graceful recovery or termination.

Example: Playing a Video with Cue Points and Ads

Example: VPAID Ad Playback in WebView

Stack and Technologies

Technologies

Key Libraries and Frameworks

Rationale for Technology Choices

High-Level Architecture

The project is structured primarily into two modules:

Major Components

Interactions Among Components

Mermaid Component Diagram

graph TB
    UI[Activities & UI Components] -->|injects| DI[Dagger Components & Modules]
    DI --> FSM[FsmPlayer & States]
    FSM -->|controls| PlayerUI[PlayerUIController]
    FSM -->|controls| PlayerAd[PlayerAdLogicController]
    FSM -->|fetches| AdInterface[AdInterface Implementation]
    FSM -->|fetches| CuePointInterface[CuePointsRetriever]
    PlayerUI --> ExoPlayerContent[ExoPlayer Content Player]
    PlayerAd --> ExoPlayerAd[ExoPlayer Ad Player]
    PlayerAd --> VPAID[TubiVPAID WebView]
    UI --> UserCtrl[UserController]
    UserCtrl --> PlayerUI
    UserCtrl --> FSM

Developer Navigation

To facilitate efficient exploration and contribution, the following developer roles and starting points are suggested:

Frontend Developers

Backend / Core Developers

Ad Integration Developers

Testing and Utilities

Visual Diagrams

FSM Playback Workflow Flowchart

flowchart TD
    Start[Initialize Player]
    Start --> FetchCuePoints[Fetch Cue Points]
    FetchCuePoints -->|Has Preroll Ad| MakePrerollAdCall[Make Preroll Ad Call]
    FetchCuePoints -->|No Preroll Ad| MoviePlaying[Play Movie]
    MakePrerollAdCall --> ReceivePrerollAd[Receive Preroll Ad]
    ReceivePrerollAd --> PlayPrerollAd[Play Preroll Ad]
    PlayPrerollAd --> MoviePlaying
    MoviePlaying --> CheckCuePoints[Check Cue Points During Playback]
    CheckCuePoints -->|Cue Point Reached| MakeAdCall[Make Midroll Ad Call]
    MakeAdCall --> ReceiveAd[Receive Ad]
    ReceiveAd --> PlayAd[Play Ad]
    PlayAd --> MoviePlaying
    MoviePlaying --> End[Movie Finished]
    PlayAd -->|Ad Finished| MoviePlaying
    PlayPrerollAd -->|Ad Finished| MoviePlaying
    MakeAdCall -->|No Ad| MoviePlaying
    FetchCuePoints -->|Error| ErrorState[Error Handling]
    MakePrerollAdCall -->|Error| ErrorState
    MakeAdCall -->|Error| ErrorState
    ErrorState --> End

High-Level Component Interaction Sequence

sequenceDiagram
    participant UI as UI/Activities
    participant DI as Dagger DI
    participant FSM as FsmPlayer
    participant AdSvc as Ad Server Interface
    participant PlayerUI as PlayerUIController
    participant PlayerAd as PlayerAdLogicController
    participant ExoContent as ExoPlayer Content
    participant ExoAd as ExoPlayer Ad
    participant VPAID as VPAID WebView

    UI->>DI: Request FSM and Controllers
    DI->>FSM: Provide FsmPlayer instance
    UI->>FSM: Load MediaModel
    FSM->>AdSvc: Fetch Cue Points
    AdSvc-->>FSM: Cue Points Data
    FSM->>FSM: Transition States (e.g. preroll ad)
    FSM->>AdSvc: Fetch Ads
    AdSvc-->>FSM: Ads Data
    FSM->>PlayerAd: Control Ad Playback
    PlayerAd->>ExoAd: Play Ad Media
    FSM->>PlayerUI: Update Playback UI
    UI->>PlayerUI: User Controls Interaction
    PlayerUI->>FSM: Control Playback (play/pause/seek)
    FSM->>ExoContent: Play Content Media
    FSM->>VPAID: Play VPAID Ad via WebView
    VPAID-->>FSM: Notify Ad Events (end/error)

This overview provides a clear roadmap for developers to understand the software architecture, key components, workflows, and technology stack. It facilitates quick onboarding and effective contribution across frontend, backend, ad integration, and testing domains.