# ExponentialWeightedAverageTimeToFirstByteEstimator

# ExponentialWeightedAverageTimeToFirstByteEstimator

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

*** ** * ** ***

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

<br />

```
@UnstableApi
class ExponentialWeightedAverageTimeToFirstByteEstimator : TimeToFirstByteEstimator
```

<br />

*** ** * ** ***

Implementation of[TimeToFirstByteEstimator](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/TimeToFirstByteEstimator)based on exponential weighted average.

## Summary

|                                       ### Constants                                       |
|-------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Double](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html) | [DEFAULT_SMOOTHING_FACTOR](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExponentialWeightedAverageTimeToFirstByteEstimator#DEFAULT_SMOOTHING_FACTOR())` = 0.85` The default smoothing factor. |

|                                                                                                                                                                                                                                         ### Public constructors                                                                                                                                                                                                                                         |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ExponentialWeightedAverageTimeToFirstByteEstimator](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExponentialWeightedAverageTimeToFirstByteEstimator#ExponentialWeightedAverageTimeToFirstByteEstimator())`()` Creates an instance using the[DEFAULT_SMOOTHING_FACTOR](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExponentialWeightedAverageTimeToFirstByteEstimator#DEFAULT_SMOOTHING_FACTOR()). |
| [ExponentialWeightedAverageTimeToFirstByteEstimator](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExponentialWeightedAverageTimeToFirstByteEstimator#ExponentialWeightedAverageTimeToFirstByteEstimator(double))`(` ` smoothingFactor: `[Double](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html) `)` Creates an instance.                                                                                                    |

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | [getTimeToFirstByteEstimateUs](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExponentialWeightedAverageTimeToFirstByteEstimator#getTimeToFirstByteEstimateUs())`()` Returns the estimated time to first byte of the response body, in microseconds, or[TIME_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#TIME_UNSET())if no estimate is available. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onTransferInitializing](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExponentialWeightedAverageTimeToFirstByteEstimator#onTransferInitializing(androidx.media3.datasource.DataSpec))`(dataSpec: `[DataSpec](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec)`!)` 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/ExponentialWeightedAverageTimeToFirstByteEstimator#onTransferStart(androidx.media3.datasource.DataSpec))`(dataSpec: `[DataSpec](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec)`!)` Called when a transfer starts.                                                               |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [reset](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExponentialWeightedAverageTimeToFirstByteEstimator#reset())`()` Resets the estimator.                                                                                                                                                                                                                                          |

## Constants

### DEFAULT_SMOOTHING_FACTOR

```
const val DEFAULT_SMOOTHING_FACTOR = 0.85: Double
```

The default smoothing factor.  

## Public constructors

### ExponentialWeightedAverageTimeToFirstByteEstimator

```
ExponentialWeightedAverageTimeToFirstByteEstimator()
```

Creates an instance using the[DEFAULT_SMOOTHING_FACTOR](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/ExponentialWeightedAverageTimeToFirstByteEstimator#DEFAULT_SMOOTHING_FACTOR()).  

### ExponentialWeightedAverageTimeToFirstByteEstimator

```
ExponentialWeightedAverageTimeToFirstByteEstimator(
    smoothingFactor: Double
)
```

Creates an instance.  

|                                              Parameters                                              |
|------------------------------------------------------------------------------------------------------|----------------------------------------------------|
| `smoothingFactor: `[Double](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html) | The exponential weighted average smoothing factor. |

## Public functions

### getTimeToFirstByteEstimateUs

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

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

### onTransferInitializing

```
fun onTransferInitializing(dataSpec: DataSpec!): Unit
```

Called when a transfer is being initialized.  

|                                                  Parameters                                                   |
|---------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------|
| `dataSpec: `[DataSpec](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec)`!` | Describes the data for which the transfer is initialized. |

### onTransferStart

```
fun onTransferStart(dataSpec: DataSpec!): Unit
```

Called when a transfer starts.  

|                                                  Parameters                                                   |
|---------------------------------------------------------------------------------------------------------------|---------------------------------------|
| `dataSpec: `[DataSpec](https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec)`!` | Describes the data being transferred. |

### reset

```
fun reset(): Unit
```

Resets the estimator.