public interface

BandwidthEstimator

 androidx.media3.exoplayer.upstream.experimental.BandwidthEstimator

Subclasses:

SplitParallelSampleBandwidthEstimator, CombinedParallelSampleBandwidthEstimator

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

The interface for different bandwidth estimation strategies.

Summary

Fields
public static final longESTIMATE_NOT_AVAILABLE

Methods
public voidaddEventListener(Handler eventHandler, BandwidthMeter.EventListener eventListener)

Adds an .

public longgetBandwidthEstimate()

Returns the bandwidth estimate in bits per second, or BandwidthEstimator.ESTIMATE_NOT_AVAILABLE if there is no estimate available yet.

public voidonBytesTransferred(DataSource source, int bytesTransferred)

Called incrementally during a transfer.

public voidonNetworkTypeChange(long newBandwidthEstimate)

Notifies this estimator that a network change has been detected.

public voidonTransferEnd(DataSource source)

Called when a transfer ends.

public voidonTransferInitializing(DataSource source)

Called when a transfer is being initialized.

public voidonTransferStart(DataSource source)

Called when a transfer starts.

public voidremoveEventListener(BandwidthMeter.EventListener eventListener)

Removes an .

Fields

public static final long ESTIMATE_NOT_AVAILABLE

Methods

public void addEventListener(Handler eventHandler, BandwidthMeter.EventListener eventListener)

Adds an .

Parameters:

eventHandler: A handler for events.
eventListener: A listener of events.

public void removeEventListener(BandwidthMeter.EventListener eventListener)

Removes an .

Parameters:

eventListener: The listener to be removed.

public void onTransferInitializing(DataSource source)

Called when a transfer is being initialized.

Parameters:

source: The DataSource performing the transfer.

public void onTransferStart(DataSource source)

Called when a transfer starts.

Parameters:

source: The DataSource performing the transfer.

public void onBytesTransferred(DataSource source, int bytesTransferred)

Called incrementally during a transfer.

Parameters:

source: The DataSource performing the transfer.
bytesTransferred: The number of bytes transferred since the previous call to this method

public void onTransferEnd(DataSource source)

Called when a transfer ends.

Parameters:

source: The DataSource performing the transfer.

public long getBandwidthEstimate()

Returns the bandwidth estimate in bits per second, or BandwidthEstimator.ESTIMATE_NOT_AVAILABLE if there is no estimate available yet.

public void onNetworkTypeChange(long newBandwidthEstimate)

Notifies this estimator that a network change has been detected.

Parameters:

newBandwidthEstimate: The new initial bandwidth estimate based on network type.

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.upstream.experimental;

import android.os.Handler;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.DataSource;
import androidx.media3.exoplayer.upstream.BandwidthMeter;

/** The interface for different bandwidth estimation strategies. */
@UnstableApi
public interface BandwidthEstimator {

  long ESTIMATE_NOT_AVAILABLE = Long.MIN_VALUE;

  /**
   * Adds an {@link BandwidthMeter.EventListener}.
   *
   * @param eventHandler A handler for events.
   * @param eventListener A listener of events.
   */
  void addEventListener(Handler eventHandler, BandwidthMeter.EventListener eventListener);

  /**
   * Removes an {@link BandwidthMeter.EventListener}.
   *
   * @param eventListener The listener to be removed.
   */
  void removeEventListener(BandwidthMeter.EventListener eventListener);

  /**
   * Called when a transfer is being initialized.
   *
   * @param source The {@link DataSource} performing the transfer.
   */
  void onTransferInitializing(DataSource source);

  /**
   * Called when a transfer starts.
   *
   * @param source The {@link DataSource} performing the transfer.
   */
  void onTransferStart(DataSource source);

  /**
   * Called incrementally during a transfer.
   *
   * @param source The {@link DataSource} performing the transfer.
   * @param bytesTransferred The number of bytes transferred since the previous call to this method
   */
  void onBytesTransferred(DataSource source, int bytesTransferred);

  /**
   * Called when a transfer ends.
   *
   * @param source The {@link DataSource} performing the transfer.
   */
  void onTransferEnd(DataSource source);

  /**
   * Returns the bandwidth estimate in bits per second, or {@link #ESTIMATE_NOT_AVAILABLE} if there
   * is no estimate available yet.
   */
  long getBandwidthEstimate();

  /**
   * Notifies this estimator that a network change has been detected.
   *
   * @param newBandwidthEstimate The new initial bandwidth estimate based on network type.
   */
  void onNetworkTypeChange(long newBandwidthEstimate);
}