# BandwidthEstimator

# BandwidthEstimator

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator "View this page in Java")

<br />

```
@UnstableApi
interface BandwidthEstimator
```

<br />

Known direct subclasses  
[CombinedParallelSampleBandwidthEstimator](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/CombinedParallelSampleBandwidthEstimator),[SplitParallelSampleBandwidthEstimator](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SplitParallelSampleBandwidthEstimator)  

|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [CombinedParallelSampleBandwidthEstimator](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/CombinedParallelSampleBandwidthEstimator) | A[BandwidthEstimator](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator)that captures a transfer sample each time all parallel transfers end. |
| [SplitParallelSampleBandwidthEstimator](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SplitParallelSampleBandwidthEstimator)       | A[BandwidthEstimator](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator)that captures a transfer sample each time a transfer ends.            |

*** ** * ** ***

The interface for different bandwidth estimation strategies.

## Summary

|                                     ### Constants                                     |
|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | [ESTIMATE_NOT_AVAILABLE](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#ESTIMATE_NOT_AVAILABLE())` = -9223372036854775808` |

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [addEventListener](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#addEventListener(android.os.Handler,androidx.media3.exoplayer.upstream.BandwidthMeter.EventListener))`(` ` eventHandler: `[Handler](https://developer.android.com/reference/android/os/Handler.html)`!,` ` eventListener: `[BandwidthMeter.EventListener](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener)`!` `)` Adds an[BandwidthMeter.EventListener](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener). |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | [getBandwidthEstimate](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#getBandwidthEstimate())`()` Returns the bandwidth estimate in bits per second, or[ESTIMATE_NOT_AVAILABLE](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#ESTIMATE_NOT_AVAILABLE())if there is no estimate available yet.                                                                                                                                                                                                                                         |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onBytesTransferred](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#onBytesTransferred(androidx.media3.datasource.DataSource,int))`(source: `[DataSource](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource)`!, bytesTransferred: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Called incrementally during a transfer.                                                                                                                                                                                                              |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onNetworkTypeChange](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#onNetworkTypeChange(long))`(newBandwidthEstimate: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Notifies this estimator that a network change has been detected.                                                                                                                                                                                                                                                                                                                                 |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onTransferEnd](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#onTransferEnd(androidx.media3.datasource.DataSource))`(source: `[DataSource](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource)`!)` Called when a transfer ends.                                                                                                                                                                                                                                                                                                                                        |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onTransferInitializing](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#onTransferInitializing(androidx.media3.datasource.DataSource))`(source: `[DataSource](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource)`!)` Called when a transfer is being initialized.                                                                                                                                                                                                                                                                                                      |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onTransferStart](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#onTransferStart(androidx.media3.datasource.DataSource))`(source: `[DataSource](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource)`!)` Called when a transfer starts.                                                                                                                                                                                                                                                                                                                                  |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [removeEventListener](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#removeEventListener(androidx.media3.exoplayer.upstream.BandwidthMeter.EventListener))`(eventListener: `[BandwidthMeter.EventListener](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener)`!)` Removes an[BandwidthMeter.EventListener](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener).                                                                                                                  |

## Constants

### ESTIMATE_NOT_AVAILABLE

```
const val ESTIMATE_NOT_AVAILABLE = -9223372036854775808: Long
```  

## Public functions

### addEventListener

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

Adds an[BandwidthMeter.EventListener](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener).  

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

### getBandwidthEstimate

```
fun getBandwidthEstimate(): Long
```

Returns the bandwidth estimate in bits per second, or[ESTIMATE_NOT_AVAILABLE](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#ESTIMATE_NOT_AVAILABLE())if there is no estimate available yet.  

### onBytesTransferred

```
fun onBytesTransferred(source: DataSource!, bytesTransferred: Int): Unit
```

Called incrementally during a transfer.  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
| `source: `[DataSource](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource)`!` | The[DataSource](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource)performing the transfer. |
| `bytesTransferred: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                 | The number of bytes transferred since the previous call to this method                                                        |

### onNetworkTypeChange

```
fun onNetworkTypeChange(newBandwidthEstimate: Long): Unit
```

Notifies this estimator that a network change has been detected.  

|                                              Parameters                                               |
|-------------------------------------------------------------------------------------------------------|-----------------------------------------------------------|
| `newBandwidthEstimate: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The new initial bandwidth estimate based on network type. |

### onTransferEnd

```
fun onTransferEnd(source: DataSource!): Unit
```

Called when a transfer ends.  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
| `source: `[DataSource](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource)`!` | The[DataSource](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource)performing the transfer. |

### onTransferInitializing

```
fun onTransferInitializing(source: DataSource!): Unit
```

Called when a transfer is being initialized.  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
| `source: `[DataSource](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource)`!` | The[DataSource](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource)performing the transfer. |

### onTransferStart

```
fun onTransferStart(source: DataSource!): Unit
```

Called when a transfer starts.  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
| `source: `[DataSource](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource)`!` | The[DataSource](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource)performing the transfer. |

### removeEventListener

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

Removes an[BandwidthMeter.EventListener](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/BandwidthMeter.EventListener).  

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