Playback Activity Base

Purpose

The Playback Activity Base defines a foundational activity that manages the lifecycle of a primary media player instance responsible for video content playback. It addresses the need for a reusable, extensible activity that encapsulates core setup and teardown of the ExoPlayer instance, media source preparation (including adaptive streaming and subtitle handling), and UI initialization. This base activity abstracts common playback concerns, enabling subclasses to customize user interaction views, caption preferences, and player readiness callbacks without re-implementing low-level player management.

Functionality

Key Methods Overview

protected void initMoviePlayer() {
    // Initializes track selector with adaptive track selection
    // Creates SimpleExoPlayer instance and associates event logger
    // Binds player to TubiExoPlayerView and sets media model
}

protected MediaSource buildMediaSource(MediaModel model) {
    // Infers media type and constructs appropriate MediaSource
    // Adds subtitle source if available by merging
    // Returns the final MediaSource for playback
}

protected void releaseMoviePlayer() {
    // Releases player resources and saves resume position
    // Resets player and track selector references
}

protected void setupExo() {
    // Calls initMoviePlayer, sets captions, marks active state,
    // and triggers subclass callback onPlayerReady()
}

Integration

This base activity serves as the core foundation for all playback activities within the media player system. It integrates tightly with:

By encapsulating these responsibilities, the Playback Activity Base minimizes duplication and enforces consistent lifecycle and media handling across multiple player activities, such as those implementing dual-player setups or advanced ad logic.

Diagram

The following flowchart illustrates the core lifecycle and setup process managed by the Playback Activity Base:

flowchart TD
    A[Activity Created] --> B[Parse Intent for MediaModel]
    B --> C[Initialize Layout & Views]
    C --> D[onStart / onResume Trigger]
    D --> E[Setup ExoPlayer]
    E --> F[Initialize TrackSelector & Player]
    F --> G[Build MediaSource from MediaModel]
    G --> H[Bind Player to UI & Set Captions]
    H --> I[Notify Subclass: onPlayerReady()]
    I --> J[User Interaction Enabled]
    J --> K[Playback Active]

    K --> L[onPause / onStop Trigger]
    L --> M[Release Player Resources]
    M --> N[Save Resume Position]
    N --> O[Playback Inactive]

This process ensures that media playback is correctly initialized, UI is prepared for interaction, and resources are properly cleaned up when the activity lifecycle demands it.