PlayerDeviceUtils.java


Overview

`PlayerDeviceUtils` is a utility class designed to provide device-specific playback behavior information within the media playback system. Its primary purpose is to detect whether the current Android device is a television or a Fire TV device, and based on this detection, decide if the media player should run as a single instance or multiple instances.

This decision is essential due to hardware and platform-specific constraints:

By encapsulating this logic, `PlayerDeviceUtils` ensures stable and optimized playback experiences tailored for different hardware environments.


Class: PlayerDeviceUtils

public class PlayerDeviceUtils {
    // ...
}

Description

A final utility class with static methods to:

This class caches the detected device type to avoid redundant system calls.


Constants

Constant Name

Description

`TAG`

Logging tag (class simple name).

`XIAOMI_MANUFACTURER`

The string `"Xiaomi"` to identify Xiaomi devices.

`MI_BOX_DEVICE`

The device model string `"once"` identifying Mi Box.

`AMAZON_FEATURE_FIRE_TV`

System feature string `"amazon.hardware.fire_tv"` to detect Fire TV devices.

`sIsTVDevice`

Cached `Boolean` indicating if device is a TV (nullable initially).


Methods

1. public static boolean isTVDevice(final Context context)

**Purpose:** Detects if the current device is a television or Amazon Fire TV.

**Parameters:**

**Returns:**

**Behavior:**

**Example Usage:**

if (PlayerDeviceUtils.isTVDevice(context)) {
    // Adjust UI or playback for TV
}

2. public static boolean useSinglePlayer()

**Purpose:** Determines if the playback system should use a single ExoPlayer instance to handle both content and ads, instead of using separate players.

**Parameters:**

**Returns:**

**Logic:**

**Important Note:**

**Example Usage:**

if (PlayerDeviceUtils.useSinglePlayer()) {
    // Initialize a single ExoPlayer instance for both content and ads
} else {
    // Use separate player instances for content and ads
}

Implementation Details


Interaction with Other System Components


Usage Example

public void initializePlayer(Context context) {
    if (PlayerDeviceUtils.isTVDevice(context)) {
        Log.d("PlayerInit", "Device is TV, using single player");
    }
    if (PlayerDeviceUtils.useSinglePlayer()) {
        // Setup single ExoPlayer for content and ads
    } else {
        // Setup dual ExoPlayer instances
    }
}

Mermaid Flowchart: PlayerDeviceUtils Function Relationships

flowchart TD
    A[isTVDevice(context)] --> B{Check sIsTVDevice cache}
    B -->|null| C[Query UiModeManager for TV mode]
    B -->|cached value| D[Return cached sIsTVDevice]

    C --> E{Is UI Mode TV?}
    E -->|Yes| F[Set sIsTVDevice = true]
    E -->|No| G[Check Fire TV feature]
    G --> H{Has Fire TV feature?}
    H -->|Yes| F
    H -->|No| I[Set sIsTVDevice = false]

    F --> D
    I --> D

    J[useSinglePlayer()] --> K{Is sIsTVDevice true?}
    K -->|Yes| L[Return true]
    K -->|No| M{Is Xiaomi Mi Box?}
    M -->|Yes| L
    M -->|No| N[Return false]

Summary


End of Documentation for PlayerDeviceUtils.java