DemoActivity.java

Overview

`DemoActivity.java` defines the `DemoActivity` class, which is a specialized Android activity extending from `TubiPlayerActivity`. This activity acts as a demo player for media content, leveraging the ExoPlayer media playback framework within the Tubi ecosystem. Its primary responsibility is to initialize media playback, manage user interactions with the media player (such as play/pause toggling, seeking, subtitle toggling, and quality selection), and handle ad insertion by concatenating advertisement media sources with the main media.

This file demonstrates how to extend and customize the playback experience by overriding player lifecycle callbacks and event handlers. It includes logic to create a concatenated media source combining ads and main content, as well as handling user actions like "Learn More" clicks on media ads.


Classes and Methods

DemoActivity

Extends `TubiPlayerActivity` and overrides several lifecycle and event callback methods to customize media playback behavior.

Constants

Lifecycle Methods

Player Lifecycle and Event Callbacks

Protected Helper Methods


Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Example Usage

// Starting the DemoActivity from another Activity or Context:
Intent intent = new Intent(context, DemoActivity.class);
context.startActivity(intent);

Once started, `DemoActivity` will prepare the media player, load the ads and main content, and start playback automatically when the player is ready.


Mermaid Class Diagram

classDiagram
    class DemoActivity {
        +static TAG: String
        +onCreate(savedInstanceState: Bundle)
        +onPlayerReady()
        +onProgress(mediaModel: MediaModel?, milliseconds: long, durationMillis: long)
        +onSeek(mediaModel: MediaModel?, oldPositionMillis: long, newPositionMillis: long)
        +onPlayToggle(mediaModel: MediaModel?, playing: boolean)
        +onLearnMoreClick(mediaModel: MediaModel)
        +onSubtitles(mediaModel: MediaModel?, enabled: boolean)
        +onQuality(mediaModel: MediaModel?)
        +onCuePointReceived(cuePoints: long[])
        #createMediaSource(): MediaSource
    }
    DemoActivity --|> TubiPlayerActivity

Summary

`DemoActivity.java` is a demonstration subclass of `TubiPlayerActivity` that exemplifies how to play media with ads using ExoPlayer in the Tubi media framework. It overrides key lifecycle and event callbacks to manage playback, user interactions, and ad insertion via concatenated media sources. This file serves as a customizable template for implementing media playback activities with integrated ad content and user engagement features within an Android application.