public final class

PlayerId

extends java.lang.Object

 java.lang.Object

↳androidx.media3.exoplayer.analytics.PlayerId

Gradle dependencies

compile group: 'androidx.media3', name: 'media3-exoplayer', version: '1.5.0-alpha01'

  • groupId: androidx.media3
  • artifactId: media3-exoplayer
  • version: 1.5.0-alpha01

Artifact androidx.media3:media3-exoplayer:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Identifier for a player instance.

Summary

Fields
public final java.lang.Stringname

A name to identify the player.

public static final PlayerIdUNSET

A player identifier with unset default values that can be used as a placeholder or for testing.

Constructors
publicPlayerId(LogSessionId logSessionId, java.lang.String playerName)

Creates an instance for API ≥ 31.

publicPlayerId(java.lang.String playerName)

Creates an instance for API < 31.

Methods
public booleanequals(java.lang.Object o)

public LogSessionIdgetLogSessionId()

Returns the for this player instance.

public inthashCode()

from java.lang.Objectclone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

Fields

public static final PlayerId UNSET

A player identifier with unset default values that can be used as a placeholder or for testing.

public final java.lang.String name

A name to identify the player. Use ExoPlayer.Builder.setName(String) to set the name, otherwise an empty string is used as the default.

Constructors

public PlayerId(java.lang.String playerName)

Creates an instance for API < 31.

Parameters:

playerName: The name of the player, for informational purpose only.

public PlayerId(LogSessionId logSessionId, java.lang.String playerName)

Creates an instance for API ≥ 31.

Parameters:

logSessionId: The used for this player.
playerName: The name of the player, for informational purpose only.

Methods

public boolean equals(java.lang.Object o)

public int hashCode()

public LogSessionId getLogSessionId()

Returns the for this player instance.

Source

/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.media3.exoplayer.analytics;

import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState;

import android.media.metrics.LogSessionId;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import androidx.media3.exoplayer.ExoPlayer.Builder;
import java.util.Objects;

/** Identifier for a player instance. */
@UnstableApi
public final class PlayerId {

  /**
   * A player identifier with unset default values that can be used as a placeholder or for testing.
   */
  public static final PlayerId UNSET =
      Util.SDK_INT < 31
          ? new PlayerId(/* playerName= */ "")
          : new PlayerId(LogSessionIdApi31.UNSET, /* playerName= */ "");

  /**
   * A name to identify the player. Use {@link Builder#setName(String)} to set the name, otherwise
   * an empty string is used as the default.
   */
  public final String name;

  @Nullable private final LogSessionIdApi31 logSessionIdApi31;

  /**
   * An object used for equals/hashCode below API 31 or when the MediaMetricsService is unavailable.
   */
  @Nullable private final Object equalityToken;

  /**
   * Creates an instance for API &lt; 31.
   *
   * @param playerName The name of the player, for informational purpose only.
   */
  public PlayerId(String playerName) {
    checkState(Util.SDK_INT < 31);
    this.name = playerName;
    this.logSessionIdApi31 = null;
    equalityToken = new Object();
  }

  /**
   * Creates an instance for API &ge; 31.
   *
   * @param logSessionId The {@link LogSessionId} used for this player.
   * @param playerName The name of the player, for informational purpose only.
   */
  @RequiresApi(31)
  public PlayerId(LogSessionId logSessionId, String playerName) {
    this(new LogSessionIdApi31(logSessionId), playerName);
  }

  private PlayerId(LogSessionIdApi31 logSessionIdApi31, String playerName) {
    this.logSessionIdApi31 = logSessionIdApi31;
    this.name = playerName;
    equalityToken = new Object();
  }

  @Override
  public boolean equals(@Nullable Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof PlayerId)) {
      return false;
    }
    PlayerId playerId = (PlayerId) o;
    return Objects.equals(name, playerId.name)
        && Objects.equals(logSessionIdApi31, playerId.logSessionIdApi31)
        && Objects.equals(equalityToken, playerId.equalityToken);
  }

  @Override
  public int hashCode() {
    return Objects.hash(name, logSessionIdApi31, equalityToken);
  }

  /** Returns the {@link LogSessionId} for this player instance. */
  @RequiresApi(31)
  public LogSessionId getLogSessionId() {
    return checkNotNull(logSessionIdApi31).logSessionId;
  }

  @RequiresApi(31)
  private static final class LogSessionIdApi31 {

    public static final LogSessionIdApi31 UNSET =
        new LogSessionIdApi31(LogSessionId.LOG_SESSION_ID_NONE);

    public final LogSessionId logSessionId;

    public LogSessionIdApi31(LogSessionId logSessionId) {
      this.logSessionId = logSessionId;
    }
  }
}