# DefaultBandwidthMeter

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/DefaultBandwidthMeter.java+class:androidx.media3.exoplayer.upstream.DefaultBandwidthMeter)

*** ** * ** ***

<br />

```
@UnstableApi
class DefaultBandwidthMeter : BandwidthMeter, TransferListener
```

<br />

*** ** * ** ***

Estimates bandwidth by listening to data transfers.

The bandwidth estimate is calculated using a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/SlidingPercentile` and is updated each time a transfer ends. 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/DefaultBandwidthMeter.Builder`.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter.Builder` Builder for a bandwidth meter. |
| `interface https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter.InitialBitrateSupplier` Supplies an initial bitrate estimate to the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter`. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter#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/DefaultBandwidthMeter#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/DefaultBandwidthMeter#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/DefaultBandwidthMeter#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/DefaultBandwidthMeter#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/DefaultBandwidthMeter#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/DefaultBandwidthMeter#DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI()` Default initial Wifi bitrate estimate in bits per second. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter#DEFAULT_SLIDING_WINDOW_MAX_WEIGHT() = 2000` Default maximum weight for the sliding window. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter#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 java-static https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter#getSingletonInstance(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html!)` Returns a singleton instance of a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter` with default configuration. |
| `https://developer.android.com/reference/kotlin/androidx/media3/datasource/TransferListener!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter#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/DefaultBandwidthMeter#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/DefaultBandwidthMeter#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. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter#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/DefaultBandwidthMeter#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. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter#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/DefaultBandwidthMeter#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. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/GuardedBy(value = "this") https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter#bitrateEstimate()` |

### 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.

### Inherited functions

From [androidx.media3.exoplayer.upstream.BandwidthMeter](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter#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.

## 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_SLIDING_WINDOW_MAX_WEIGHT

```
const val DEFAULT_SLIDING_WINDOW_MAX_WEIGHT = 2000: Int
```

Default maximum weight for the sliding window.

## Public functions

### addEventListener

```
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. |

### getSingletonInstance

```
synchronized java-static fun getSingletonInstance(context: Context!): DefaultBandwidthMeter!
```

Returns a singleton instance of a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter` with default configuration.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html!` | A `https://developer.android.com/reference/android/content/Context.html`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultBandwidthMeter!` | The singleton instance. |

### 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

```
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

```
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. |

## Public properties

### bitrateEstimate

```
@GuardedBy(value = "this")
val bitrateEstimate: Long
```