# ExperimentalBandwidthMeter

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter.java+class:androidx.media3.exoplayer.upstream.experimental.ExperimentalBandwidthMeter)

*** ** * ** ***

<br />

```
@ExperimentalApi
public final class ExperimentalBandwidthMeter implements BandwidthMeter, TransferListener
```

<br />

*** ** * ** ***

An experimental `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter` that estimates bandwidth by listening to data transfers.

The initial estimate is based on the current operator's network country code or the locale of the user, as well as the network connection type. This can be configured in the `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter.Builder`.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter.Builder` Builder for a bandwidth meter. |

| ### Constants |
|---|---|
| `static final long` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATE() = 1000000` Default initial bitrate estimate used when the device is offline or the network type cannot be determined, in bits per second. |
| `static final https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/java/lang/Long.html>` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATES_2G()` Default initial 2G bitrate estimates in bits per second. |
| `static final https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/java/lang/Long.html>` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATES_3G()` Default initial 3G bitrate estimates in bits per second. |
| `static final https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/java/lang/Long.html>` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATES_4G()` Default initial 4G bitrate estimates in bits per second. |
| `static final https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/java/lang/Long.html>` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA()` Default initial 5G-NSA bitrate estimates in bits per second. |
| `static final https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/java/lang/Long.html>` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA()` Default initial 5G-SA bitrate estimates in bits per second. |
| `static final https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/java/lang/Long.html>` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI()` Default initial Wifi bitrate estimate in bits per second. |
| `static final float` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_TIME_TO_FIRST_BYTE_PERCENTILE() = 0.5f` Default percentile for estimating the time to first byte. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_TIME_TO_FIRST_BYTE_SAMPLES() = 20` Default number of samples to keep in the sliding window for estimating the time to first byte. |

| ### Public methods |
|---|---|
| `synchronized void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#addEventListener(android.os.Handler,androidx.media3.exoplayer.upstream.BandwidthMeter.EventListener)( https://developer.android.com/reference/android/os/Handler.html eventHandler, https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener eventListener )` Adds an `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener`. |
| `synchronized long` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#getBitrateEstimate()()` Returns the estimated bitrate. |
| `synchronized long` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#getTimeToFirstByteEstimateUs()()` Returns the estimated time to first byte, in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if no estimate is available. |
| `https://developer.android.com/reference/androidx/media3/datasource/TransferListener` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#getTransferListener()()` Returns the `https://developer.android.com/reference/androidx/media3/datasource/TransferListener` that this instance uses to gather bandwidth information from data transfers. |
| `synchronized void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#onBytesTransferred(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,boolean,int)( https://developer.android.com/reference/androidx/media3/datasource/DataSource source, https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec, boolean isNetwork, int bytesTransferred )` Called incrementally during a transfer. |
| `synchronized void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#onTransferEnd(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,boolean)(https://developer.android.com/reference/androidx/media3/datasource/DataSource source, https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec, boolean isNetwork)` Called when a transfer ends. |
| `synchronized void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#onTransferInitializing(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,boolean)( https://developer.android.com/reference/androidx/media3/datasource/DataSource source, https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec, boolean isNetwork )` Called when a transfer is being initialized. |
| `synchronized void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#onTransferStart(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,boolean)(https://developer.android.com/reference/androidx/media3/datasource/DataSource source, https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec, boolean isNetwork)` Called when a transfer starts. |
| `synchronized void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#removeEventListener(androidx.media3.exoplayer.upstream.BandwidthMeter.EventListener)(https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener eventListener)` Removes an `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener`. |
| `synchronized void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#setNetworkTypeOverride(int)(@https://developer.android.com/reference/androidx/media3/common/C.NetworkType int networkType)` Overrides the network type. |

### Inherited Constants

From [androidx.media3.exoplayer.upstream.BandwidthMeter](https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter) `static final https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter` `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter#NO_OP()`

A no-op `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter` that doesn't do estimation.

## Constants

### DEFAULT_INITIAL_BITRATE_ESTIMATE

```
public static final long DEFAULT_INITIAL_BITRATE_ESTIMATE = 1000000
```

Default initial bitrate estimate used when the device is offline or the network type cannot be determined, in bits per second.

### DEFAULT_INITIAL_BITRATE_ESTIMATES_2G

```
public static final ImmutableList<Long> DEFAULT_INITIAL_BITRATE_ESTIMATES_2G
```

Default initial 2G bitrate estimates in bits per second.

### DEFAULT_INITIAL_BITRATE_ESTIMATES_3G

```
public static final ImmutableList<Long> DEFAULT_INITIAL_BITRATE_ESTIMATES_3G
```

Default initial 3G bitrate estimates in bits per second.

### DEFAULT_INITIAL_BITRATE_ESTIMATES_4G

```
public static final ImmutableList<Long> DEFAULT_INITIAL_BITRATE_ESTIMATES_4G
```

Default initial 4G bitrate estimates in bits per second.

### DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA

```
public static final ImmutableList<Long> DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA
```

Default initial 5G-NSA bitrate estimates in bits per second.

### DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA

```
public static final ImmutableList<Long> DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA
```

Default initial 5G-SA bitrate estimates in bits per second.

### DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI

```
public static final ImmutableList<Long> DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI
```

Default initial Wifi bitrate estimate in bits per second.

### DEFAULT_TIME_TO_FIRST_BYTE_PERCENTILE

```
public static final float DEFAULT_TIME_TO_FIRST_BYTE_PERCENTILE = 0.5f
```

Default percentile for estimating the time to first byte.

### DEFAULT_TIME_TO_FIRST_BYTE_SAMPLES

```
public static final int DEFAULT_TIME_TO_FIRST_BYTE_SAMPLES = 20
```

Default number of samples to keep in the sliding window for estimating the time to first byte.

## Public methods

### addEventListener

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

Adds an `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/os/Handler.html eventHandler` | A handler for events. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener eventListener` | A listener of events. |

### getBitrateEstimate

```
synchronized public long getBitrateEstimate()
```

Returns the estimated bitrate.

### getTimeToFirstByteEstimateUs

```
synchronized public long getTimeToFirstByteEstimateUs()
```

Returns the estimated time to first byte, in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if no estimate is available.

### getTransferListener

```
public TransferListener getTransferListener()
```

Returns the `https://developer.android.com/reference/androidx/media3/datasource/TransferListener` that this instance uses to gather bandwidth information from data transfers. May be null if the implementation does not listen to data transfers.

### onBytesTransferred

```
synchronized public void onBytesTransferred(
    DataSource source,
    DataSpec dataSpec,
    boolean isNetwork,
    int bytesTransferred
)
```

Called incrementally during a transfer.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource source` | The source performing the transfer. |
| `https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec` | Describes the data being transferred. |
| `boolean isNetwork` | Whether the data is transferred through a network. |
| `int bytesTransferred` | The number of bytes transferred since the previous call to this method. |

### onTransferEnd

```
synchronized public void onTransferEnd(DataSource source, DataSpec dataSpec, boolean isNetwork)
```

Called when a transfer ends.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource source` | The source performing the transfer. |
| `https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec` | Describes the data being transferred. |
| `boolean isNetwork` | Whether the data is transferred through a network. |

### onTransferInitializing

```
synchronized public void onTransferInitializing(
    DataSource source,
    DataSpec dataSpec,
    boolean isNetwork
)
```

Called when a transfer is being initialized.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource source` | The source performing the transfer. |
| `https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec` | Describes the data for which the transfer is initialized. |
| `boolean isNetwork` | Whether the data is transferred through a network. |

### onTransferStart

```
synchronized public void onTransferStart(DataSource source, DataSpec dataSpec, boolean isNetwork)
```

Called when a transfer starts.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource source` | The source performing the transfer. |
| `https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec` | Describes the data being transferred. |
| `boolean isNetwork` | Whether the data is transferred through a network. |

### removeEventListener

```
synchronized public void removeEventListener(BandwidthMeter.EventListener eventListener)
```

Removes an `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener eventListener` | The listener to be removed. |

### setNetworkTypeOverride

```
synchronized public void setNetworkTypeOverride(@C.NetworkType int networkType)
```

Overrides the network type. Handled in the same way as if the meter had detected a change from the current network type to the specified network type internally.

Applications should not normally call this method. It is intended for testing purposes.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/common/C.NetworkType int networkType` | The overriding network type. |