public class

Label

extends java.lang.Object

 java.lang.Object

↳androidx.media3.common.Label

Gradle dependencies

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

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

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

Overview

A label for a Format.

Summary

Fields
public final java.lang.Stringlanguage

The language of this label, as an IETF BCP 47 conformant tag, or null if unknown or not applicable.

public final java.lang.Stringvalue

The value for this label.

Constructors
publicLabel(java.lang.String language, java.lang.String value)

Creates a label.

Methods
public booleanequals(java.lang.Object o)

public static LabelfromBundle(Bundle bundle)

Deserializes an instance from a produced by Label.toBundle().

public inthashCode()

public BundletoBundle()

Serializes this instance to a .

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

Fields

public final java.lang.String language

The language of this label, as an IETF BCP 47 conformant tag, or null if unknown or not applicable.

public final java.lang.String value

The value for this label.

Constructors

public Label(java.lang.String language, java.lang.String value)

Creates a label.

Parameters:

language: The language of this label, as an IETF BCP 47 conformant tag, or null if unknown or not applicable.
value: The label value.

Methods

public boolean equals(java.lang.Object o)

public int hashCode()

public Bundle toBundle()

Serializes this instance to a .

public static Label fromBundle(Bundle bundle)

Deserializes an instance from a produced by Label.toBundle().

Source

/*
 * Copyright 2024 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.common;

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

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;

/** A label for a {@link Format}. */
@UnstableApi
public class Label {
  /**
   * The language of this label, as an IETF BCP 47 conformant tag, or null if unknown or not
   * applicable.
   */
  @Nullable public final String language;

  /** The value for this label. */
  public final String value;

  /**
   * Creates a label.
   *
   * @param language The language of this label, as an IETF BCP 47 conformant tag, or null if
   *     unknown or not applicable.
   * @param value The label value.
   */
  public Label(@Nullable String language, String value) {
    this.language = Util.normalizeLanguageCode(language);
    this.value = value;
  }

  @Override
  public boolean equals(@Nullable Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    Label label = (Label) o;
    return Util.areEqual(language, label.language) && Util.areEqual(value, label.value);
  }

  @Override
  public int hashCode() {
    int result = value.hashCode();
    result = 31 * result + (language != null ? language.hashCode() : 0);
    return result;
  }

  private static final String FIELD_LANGUAGE_INDEX = Util.intToStringMaxRadix(0);
  private static final String FIELD_VALUE_INDEX = Util.intToStringMaxRadix(1);

  /** Serializes this instance to a {@link Bundle}. */
  public Bundle toBundle() {
    Bundle bundle = new Bundle();
    if (language != null) {
      bundle.putString(FIELD_LANGUAGE_INDEX, language);
    }
    bundle.putString(FIELD_VALUE_INDEX, value);
    return bundle;
  }

  /** Deserializes an instance from a {@link Bundle} produced by {@link #toBundle()}. */
  public static Label fromBundle(Bundle bundle) {
    return new Label(
        bundle.getString(FIELD_LANGUAGE_INDEX), checkNotNull(bundle.getString(FIELD_VALUE_INDEX)));
  }
}