public final class

MediaParserUtil

extends java.lang.Object

 java.lang.Object

↳androidx.media3.exoplayer.source.mediaparser.MediaParserUtil

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

Miscellaneous constants and utility methods related to the MediaParser integration.

For documentation on constants, please see the MediaParser documentation.

Summary

Fields
public static final java.lang.StringPARAMETER_EAGERLY_EXPOSE_TRACK_TYPE

public static final java.lang.StringPARAMETER_EXPOSE_CAPTION_FORMATS

public static final java.lang.StringPARAMETER_EXPOSE_CHUNK_INDEX_AS_MEDIA_FORMAT

public static final java.lang.StringPARAMETER_EXPOSE_DUMMY_SEEK_MAP

public static final java.lang.StringPARAMETER_IGNORE_TIMESTAMP_OFFSET

public static final java.lang.StringPARAMETER_IN_BAND_CRYPTO_INFO

public static final java.lang.StringPARAMETER_INCLUDE_SUPPLEMENTAL_DATA

public static final java.lang.StringPARAMETER_OVERRIDE_IN_BAND_CAPTION_DECLARATIONS

Methods
public static voidsetLogSessionIdOnMediaParser(MediaParser mediaParser, PlayerId playerId)

Calls MediaParser.

public static MediaFormattoCaptionsMediaFormat(Format format)

Returns a with equivalent and to the given Format.

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

Fields

public static final java.lang.String PARAMETER_IN_BAND_CRYPTO_INFO

public static final java.lang.String PARAMETER_INCLUDE_SUPPLEMENTAL_DATA

public static final java.lang.String PARAMETER_EAGERLY_EXPOSE_TRACK_TYPE

public static final java.lang.String PARAMETER_EXPOSE_DUMMY_SEEK_MAP

public static final java.lang.String PARAMETER_EXPOSE_CHUNK_INDEX_AS_MEDIA_FORMAT

public static final java.lang.String PARAMETER_OVERRIDE_IN_BAND_CAPTION_DECLARATIONS

public static final java.lang.String PARAMETER_EXPOSE_CAPTION_FORMATS

public static final java.lang.String PARAMETER_IGNORE_TIMESTAMP_OFFSET

Methods

public static MediaFormat toCaptionsMediaFormat(Format format)

Returns a with equivalent and to the given Format.

public static void setLogSessionIdOnMediaParser(MediaParser mediaParser, PlayerId playerId)

Calls MediaParser.

Parameters:

mediaParser: The MediaParser to call the method on.
playerId: The PlayerId to obtain the from.

Source

/*
 * Copyright 2020 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.source.mediaparser;

import android.media.MediaFormat;
import android.media.MediaParser;
import android.media.metrics.LogSessionId;
import androidx.annotation.DoNotInline;
import androidx.annotation.RequiresApi;
import androidx.media3.common.Format;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.exoplayer.analytics.PlayerId;

/**
 * Miscellaneous constants and utility methods related to the {@link MediaParser} integration.
 *
 * <p>For documentation on constants, please see the {@link MediaParser} documentation.
 */
@UnstableApi
public final class MediaParserUtil {

  public static final String PARAMETER_IN_BAND_CRYPTO_INFO =
      "android.media.mediaparser.inBandCryptoInfo";
  public static final String PARAMETER_INCLUDE_SUPPLEMENTAL_DATA =
      "android.media.mediaparser.includeSupplementalData";
  public static final String PARAMETER_EAGERLY_EXPOSE_TRACK_TYPE =
      "android.media.mediaparser.eagerlyExposeTrackType";
  public static final String PARAMETER_EXPOSE_DUMMY_SEEK_MAP =
      "android.media.mediaparser.exposeDummySeekMap";
  public static final String PARAMETER_EXPOSE_CHUNK_INDEX_AS_MEDIA_FORMAT =
      "android.media.mediaParser.exposeChunkIndexAsMediaFormat";
  public static final String PARAMETER_OVERRIDE_IN_BAND_CAPTION_DECLARATIONS =
      "android.media.mediaParser.overrideInBandCaptionDeclarations";
  public static final String PARAMETER_EXPOSE_CAPTION_FORMATS =
      "android.media.mediaParser.exposeCaptionFormats";
  public static final String PARAMETER_IGNORE_TIMESTAMP_OFFSET =
      "android.media.mediaparser.ignoreTimestampOffset";

  private MediaParserUtil() {}

  /**
   * Returns a {@link MediaFormat} with equivalent {@link MediaFormat#KEY_MIME} and {@link
   * MediaFormat#KEY_CAPTION_SERVICE_NUMBER} to the given {@link Format}.
   */
  public static MediaFormat toCaptionsMediaFormat(Format format) {
    MediaFormat mediaFormat = new MediaFormat();
    mediaFormat.setString(MediaFormat.KEY_MIME, format.sampleMimeType);
    if (format.accessibilityChannel != Format.NO_VALUE) {
      mediaFormat.setInteger(MediaFormat.KEY_CAPTION_SERVICE_NUMBER, format.accessibilityChannel);
    }
    return mediaFormat;
  }

  /**
   * Calls {@link MediaParser#setLogSessionId(LogSessionId)}.
   *
   * @param mediaParser The {@link MediaParser} to call the method on.
   * @param playerId The {@link PlayerId} to obtain the {@link LogSessionId} from.
   */
  @RequiresApi(31)
  public static void setLogSessionIdOnMediaParser(MediaParser mediaParser, PlayerId playerId) {
    Api31.setLogSessionIdOnMediaParser(mediaParser, playerId);
  }

  @RequiresApi(31)
  private static final class Api31 {
    private Api31() {}

    @DoNotInline
    public static void setLogSessionIdOnMediaParser(MediaParser mediaParser, PlayerId playerId) {
      LogSessionId logSessionId = playerId.getLogSessionId();
      if (!logSessionId.equals(LogSessionId.LOG_SESSION_ID_NONE)) {
        mediaParser.setLogSessionId(logSessionId);
      }
    }
  }
}