# 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
class ExperimentalBandwidthMeter : BandwidthMeter, TransferListener
```

<br />

*** ** * ** ***

An experimental `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter.Builder`.

## Summary

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

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/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. |
| `const https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATES_2G()` Default initial 2G bitrate estimates in bits per second. |
| `const https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATES_3G()` Default initial 3G bitrate estimates in bits per second. |
| `const https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATES_4G()` Default initial 4G bitrate estimates in bits per second. |
| `const https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA()` Default initial 5G-NSA bitrate estimates in bits per second. |
| `const https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA()` Default initial 5G-SA bitrate estimates in bits per second. |
| `const https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html!>!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI()` Default initial Wifi bitrate estimate in bits per second. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#DEFAULT_TIME_TO_FIRST_BYTE_PERCENTILE() = 0.5f` Default percentile for estimating the time to first byte. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/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 functions |
|---|---|
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#addEventListener(android.os.Handler,androidx.media3.exoplayer.upstream.BandwidthMeter.EventListener)( eventHandler: https://developer.android.com/reference/android/os/Handler.html!, eventListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener! )` Adds an `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener`. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#getBitrateEstimate()()` Returns the estimated bitrate. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#getTimeToFirstByteEstimateUs()()` Returns the estimated time to first byte, in microseconds, or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#TIME_UNSET()` if no estimate is available. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/TransferListener!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#getTransferListener()()` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/datasource/TransferListener` that this instance uses to gather bandwidth information from data transfers. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#onBytesTransferred(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,boolean,int)( source: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, dataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!, isNetwork: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, bytesTransferred: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Called incrementally during a transfer. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#onTransferEnd(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,boolean)(source: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, dataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!, isNetwork: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Called when a transfer ends. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#onTransferInitializing(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,boolean)( source: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, dataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!, isNetwork: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Called when a transfer is being initialized. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#onTransferStart(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,boolean)(source: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, dataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!, isNetwork: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Called when a transfer starts. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#removeEventListener(androidx.media3.exoplayer.upstream.BandwidthMeter.EventListener)(eventListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener!)` Removes an `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener`. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExperimentalBandwidthMeter#setNetworkTypeOverride(int)(@https://developer.android.com/reference/kotlin/androidx/media3/common/C.NetworkType networkType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Overrides the network type. |

### Inherited Constants

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

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

## Constants

### DEFAULT_INITIAL_BITRATE_ESTIMATE

```
const val DEFAULT_INITIAL_BITRATE_ESTIMATE = 1000000: Long
```

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

```
const val DEFAULT_INITIAL_BITRATE_ESTIMATES_2G: ImmutableList<Long!>!
```

Default initial 2G bitrate estimates in bits per second.

### DEFAULT_INITIAL_BITRATE_ESTIMATES_3G

```
const val DEFAULT_INITIAL_BITRATE_ESTIMATES_3G: ImmutableList<Long!>!
```

Default initial 3G bitrate estimates in bits per second.

### DEFAULT_INITIAL_BITRATE_ESTIMATES_4G

```
const val DEFAULT_INITIAL_BITRATE_ESTIMATES_4G: ImmutableList<Long!>!
```

Default initial 4G bitrate estimates in bits per second.

### DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA

```
const val DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA: ImmutableList<Long!>!
```

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

### DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA

```
const val DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA: ImmutableList<Long!>!
```

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

### DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI

```
const val DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI: ImmutableList<Long!>!
```

Default initial Wifi bitrate estimate in bits per second.

### DEFAULT_TIME_TO_FIRST_BYTE_PERCENTILE

```
const val DEFAULT_TIME_TO_FIRST_BYTE_PERCENTILE = 0.5f: Float
```

Default percentile for estimating the time to first byte.

### DEFAULT_TIME_TO_FIRST_BYTE_SAMPLES

```
const val DEFAULT_TIME_TO_FIRST_BYTE_SAMPLES = 20: Int
```

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

## Public functions

### addEventListener

```
synchronized fun addEventListener(
    eventHandler: Handler!,
    eventListener: BandwidthMeter.EventListener!
): Unit
```

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

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

### getBitrateEstimate

```
synchronized fun getBitrateEstimate(): Long
```

Returns the estimated bitrate.

### getTimeToFirstByteEstimateUs

```
synchronized fun getTimeToFirstByteEstimateUs(): Long
```

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

### getTransferListener

```
fun getTransferListener(): TransferListener!
```

Returns the `https://developer.android.com/reference/kotlin/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 fun onBytesTransferred(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean,
    bytesTransferred: Int
): Unit
```

Called incrementally during a transfer.

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

### onTransferEnd

```
synchronized fun onTransferEnd(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean): Unit
```

Called when a transfer ends.

| Parameters |
|---|---|
| `source: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` | The source performing the transfer. |
| `dataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!` | Describes the data being transferred. |
| `isNetwork: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the data is transferred through a network. |

### onTransferInitializing

```
synchronized fun onTransferInitializing(
    source: DataSource!,
    dataSpec: DataSpec!,
    isNetwork: Boolean
): Unit
```

Called when a transfer is being initialized.

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

### onTransferStart

```
synchronized fun onTransferStart(source: DataSource!, dataSpec: DataSpec!, isNetwork: Boolean): Unit
```

Called when a transfer starts.

| Parameters |
|---|---|
| `source: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` | The source performing the transfer. |
| `dataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!` | Describes the data being transferred. |
| `isNetwork: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the data is transferred through a network. |

### removeEventListener

```
synchronized fun removeEventListener(eventListener: BandwidthMeter.EventListener!): Unit
```

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

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

### setNetworkTypeOverride

```
synchronized fun setNetworkTypeOverride(@C.NetworkType networkType: Int): Unit
```

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/kotlin/androidx/media3/common/C.NetworkType networkType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The overriding network type. |