Media Helper Utilities

Purpose

Media Helper Utilities address the need for consistent, efficient construction of ExoPlayer data source factories within the media playback system. This subtopic focuses on creating reusable methods that encapsulate the setup of network data sources with bandwidth metering support, which is essential for adaptive streaming and accurate network usage tracking. Unlike the parent topic’s broader scope of media models and device utilities, this subtopic zeroes in on facilitating the building blocks for media loading pipelines, enabling other components to seamlessly acquire properly configured data sources.

Functionality

The key functionality provided by Media Helper Utilities lies in static factory methods that produce:

The main workflows involve:

This modular approach allows various player components to request data source factories without duplicating setup logic or managing bandwidth metering manually. It also centralizes user agent configuration, improving maintainability.

Example snippet illustrating core factory creation:

public static @NonNull DataSource.Factory buildDataSourceFactory(
        @NonNull Context context,
        @Nullable DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultDataSourceFactory(context, bandwidthMeter,
            buildHttpDataSourceFactory(context, bandwidthMeter));
}

public static @NonNull HttpDataSource.Factory buildHttpDataSourceFactory(
        @NonNull Context context,
        @NonNull DefaultBandwidthMeter bandwidthMeter) {
    return new DefaultHttpDataSourceFactory(Util.getUserAgent(context, "TubiExoPlayer"), bandwidthMeter);
}

Integration

Media Helper Utilities serve as foundational support within the parent topic's ecosystem of media models and playback helpers by:

By encapsulating this setup, it reduces redundancy in other subtopics and simplifies the integration of new media types or streaming protocols. This utility thus acts as a shared service that connects media definition layers (media models) to playback execution layers (ExoPlayer and FSM).

Diagram

flowchart TD
    A[Playback Component] -->|Requests DataSource Factory| B[Media Helper Utilities]
    B --> C[buildDataSourceFactory(context, bandwidthMeter)]
    C --> D[DefaultDataSourceFactory]
    D --> E[DefaultHttpDataSourceFactory]
    E --> F[Tracks Bandwidth using DefaultBandwidthMeter]
    F --> G[ExoPlayer Network Requests]

This flowchart illustrates how playback components request data source factories from Media Helper Utilities, which construct layered factories embedding bandwidth metering, ultimately supporting ExoPlayer’s network operations.