public abstract class

Chunk

extends java.lang.Object

implements Loader.Loadable

 java.lang.Object

↳androidx.media3.exoplayer.source.chunk.Chunk

Subclasses:

ContainerMediaChunk, DataChunk, SingleSampleMediaChunk, InitializationChunk, MediaChunk, BaseMediaChunk, FakeMediaChunk

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

An abstract base class for Loader.Loadable implementations that load chunks of data required for the playback of streams.

Summary

Fields
protected final StatsDataSourcedataSource

public final DataSpecdataSpec

The DataSpec that defines the data to be loaded.

public final longendTimeUs

The end time of the media contained by the chunk, or C.TIME_UNSET if the data being loaded does not contain media samples.

public final longloadTaskId

Identifies the load task for this loadable.

public final longstartTimeUs

The start time of the media contained by the chunk, or C.TIME_UNSET if the data being loaded does not contain media samples.

public final FormattrackFormat

The format of the track to which this chunk belongs.

public final java.lang.ObjecttrackSelectionData

Optional data associated with the selection of the track to which this chunk belongs.

public final inttrackSelectionReason

One of the if the chunk belongs to a track.

public final inttype

The data type of the chunk.

Constructors
publicChunk(DataSource dataSource, DataSpec dataSpec, int type, Format trackFormat, int trackSelectionReason, java.lang.Object trackSelectionData, long startTimeUs, long endTimeUs)

Methods
public final longbytesLoaded()

Returns the number of bytes that have been loaded.

public final longgetDurationUs()

Returns the duration of the chunk in microseconds.

public final java.util.Map<java.lang.String, java.util.List>getResponseHeaders()

Returns the response headers associated with the last DataSource.open(DataSpec) call.

public final UrigetUri()

Returns the associated with the last DataSource.open(DataSpec) call.

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

Fields

public final long loadTaskId

Identifies the load task for this loadable.

public final DataSpec dataSpec

The DataSpec that defines the data to be loaded.

public final int type

The data type of the chunk. For reporting only.

public final Format trackFormat

The format of the track to which this chunk belongs.

public final int trackSelectionReason

One of the if the chunk belongs to a track. C.SELECTION_REASON_UNKNOWN if the chunk does not belong to a track, or if the selection reason is unknown.

public final java.lang.Object trackSelectionData

Optional data associated with the selection of the track to which this chunk belongs. Null if the chunk does not belong to a track, or if there is no associated track selection data.

public final long startTimeUs

The start time of the media contained by the chunk, or C.TIME_UNSET if the data being loaded does not contain media samples.

public final long endTimeUs

The end time of the media contained by the chunk, or C.TIME_UNSET if the data being loaded does not contain media samples.

protected final StatsDataSource dataSource

Constructors

public Chunk(DataSource dataSource, DataSpec dataSpec, int type, Format trackFormat, int trackSelectionReason, java.lang.Object trackSelectionData, long startTimeUs, long endTimeUs)

Parameters:

dataSource: The source from which the data should be loaded.
dataSpec: Defines the data to be loaded.
type: See Chunk.type.
trackFormat: See Chunk.trackFormat.
trackSelectionReason: See Chunk.trackSelectionReason.
trackSelectionData: See Chunk.trackSelectionData.
startTimeUs: See Chunk.startTimeUs.
endTimeUs: See Chunk.endTimeUs.

Methods

public final long getDurationUs()

Returns the duration of the chunk in microseconds.

public final long bytesLoaded()

Returns the number of bytes that have been loaded. Must only be called after the load completed, failed, or was canceled.

public final Uri getUri()

Returns the associated with the last DataSource.open(DataSpec) call. If redirection occurred, this is the redirected uri. Must only be called after the load completed, failed, or was canceled.

See also: DataSource.getUri()

public final java.util.Map<java.lang.String, java.util.List> getResponseHeaders()

Returns the response headers associated with the last DataSource.open(DataSpec) call. Must only be called after the load completed, failed, or was canceled.

See also: DataSource.getResponseHeaders()

Source

/*
 * Copyright (C) 2016 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.chunk;

import android.net.Uri;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.C.DataType;
import androidx.media3.common.Format;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.DataSource;
import androidx.media3.datasource.DataSpec;
import androidx.media3.datasource.StatsDataSource;
import androidx.media3.exoplayer.source.LoadEventInfo;
import androidx.media3.exoplayer.upstream.Loader.Loadable;
import java.util.List;
import java.util.Map;

/**
 * An abstract base class for {@link Loadable} implementations that load chunks of data required for
 * the playback of streams.
 */
@UnstableApi
public abstract class Chunk implements Loadable {

  /** Identifies the load task for this loadable. */
  public final long loadTaskId;

  /** The {@link DataSpec} that defines the data to be loaded. */
  public final DataSpec dataSpec;

  /** The {@link DataType data type} of the chunk. For reporting only. */
  public final @DataType int type;

  /** The format of the track to which this chunk belongs. */
  public final Format trackFormat;

  /**
   * One of the {@link C.SelectionReason selection reasons} if the chunk belongs to a track. {@link
   * C#SELECTION_REASON_UNKNOWN} if the chunk does not belong to a track, or if the selection reason
   * is unknown.
   */
  public final @C.SelectionReason int trackSelectionReason;

  /**
   * Optional data associated with the selection of the track to which this chunk belongs. Null if
   * the chunk does not belong to a track, or if there is no associated track selection data.
   */
  @Nullable public final Object trackSelectionData;

  /**
   * The start time of the media contained by the chunk, or {@link C#TIME_UNSET} if the data being
   * loaded does not contain media samples.
   */
  public final long startTimeUs;

  /**
   * The end time of the media contained by the chunk, or {@link C#TIME_UNSET} if the data being
   * loaded does not contain media samples.
   */
  public final long endTimeUs;

  protected final StatsDataSource dataSource;

  /**
   * @param dataSource The source from which the data should be loaded.
   * @param dataSpec Defines the data to be loaded.
   * @param type See {@link #type}.
   * @param trackFormat See {@link #trackFormat}.
   * @param trackSelectionReason See {@link #trackSelectionReason}.
   * @param trackSelectionData See {@link #trackSelectionData}.
   * @param startTimeUs See {@link #startTimeUs}.
   * @param endTimeUs See {@link #endTimeUs}.
   */
  public Chunk(
      DataSource dataSource,
      DataSpec dataSpec,
      @DataType int type,
      Format trackFormat,
      @C.SelectionReason int trackSelectionReason,
      @Nullable Object trackSelectionData,
      long startTimeUs,
      long endTimeUs) {
    this.dataSource = new StatsDataSource(dataSource);
    this.dataSpec = Assertions.checkNotNull(dataSpec);
    this.type = type;
    this.trackFormat = trackFormat;
    this.trackSelectionReason = trackSelectionReason;
    this.trackSelectionData = trackSelectionData;
    this.startTimeUs = startTimeUs;
    this.endTimeUs = endTimeUs;
    loadTaskId = LoadEventInfo.getNewId();
  }

  /** Returns the duration of the chunk in microseconds. */
  public final long getDurationUs() {
    return endTimeUs - startTimeUs;
  }

  /**
   * Returns the number of bytes that have been loaded. Must only be called after the load
   * completed, failed, or was canceled.
   */
  public final long bytesLoaded() {
    return dataSource.getBytesRead();
  }

  /**
   * Returns the {@link Uri} associated with the last {@link DataSource#open} call. If redirection
   * occurred, this is the redirected uri. Must only be called after the load completed, failed, or
   * was canceled.
   *
   * @see DataSource#getUri()
   */
  public final Uri getUri() {
    return dataSource.getLastOpenedUri();
  }

  /**
   * Returns the response headers associated with the last {@link DataSource#open} call. Must only
   * be called after the load completed, failed, or was canceled.
   *
   * @see DataSource#getResponseHeaders()
   */
  public final Map<String, List<String>> getResponseHeaders() {
    return dataSource.getLastResponseHeaders();
  }
}