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
Player Lifecycle Management
Controls creation, configuration, and release of a singleSimpleExoPlayerinstance (mMoviePlayer) tied to the activity lifecycle events (onStart,onResume,onPause,onStop). This ensures optimal resource usage and proper handling across Android SDK versions.Media Source Construction
Builds adaptive media sources based on content type (SmoothStreaming, DASH, HLS, or other formats) using ExoPlayer’s media source factories. It also merges subtitle sources if available, supporting sideloaded captions with correct format and selection flags.UI Initialization and Interaction
Sets up the main player view (TubiExoPlayerView) and integrates an abstract user interaction view provided by subclasses. Manages auxiliary UI elements such as a WebView for VPAID ads and a cue point indicator text view.Caption Handling
Toggles subtitle display according to subclass-defined caption preference, facilitating accessibility and user customization.Event Logging and Tracking
Integrates ExoPlayer’s EventLogger to monitor playback events and metadata, aiding debugging and analytics.Intent Parsing
Extracts theMediaModelfrom incoming intents to initialize playback content, enforcing presence and validity of media data.
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:
Player UI Controller and User Interaction Controller
By abstracting a methodaddUserInteractionView(), it allows subclasses to inject customized UI controls that bind to player state and user inputs.Custom Player View (
TubiExoPlayerView)
Hosts the ExoPlayer instance and subtitle rendering, providing the visual playback surface and control bindings.Finite State Machine (FSM) Playback
While this base activity manages the raw media playback instance, higher-level FSM layers orchestrate ad insertion, cue point handling, and state transitions. The base activity provides the necessary player setup and media source preparation that FSM-driven states rely on for smooth content playback.VPAID Ad Integration
Prepares a WebView component for VPAID ads, which subclasses or FSM states can control for interactive ad playback alongside content.
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.