# SlidingPercentileBandwidthStatistic

# SlidingPercentileBandwidthStatistic

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

*** ** * ** ***

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

<br />

```
@UnstableApi
class SlidingPercentileBandwidthStatistic : BandwidthStatistic
```

<br />

*** ** * ** ***

A[BandwidthStatistic](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthStatistic)that calculates estimates based on a sliding window weighted percentile.

## Summary

|                                       ### Constants                                       |
|-------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)       | [DEFAULT_MAX_SAMPLES_COUNT](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#DEFAULT_MAX_SAMPLES_COUNT())` = 10` The default maximum number of samples. |
| `const `[Double](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html) | [DEFAULT_PERCENTILE](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#DEFAULT_PERCENTILE())` = 0.5` The default percentile to return.                   |

|                                                                                                                                                                                                                                                                                                                 ### Public constructors                                                                                                                                                                                                                                                                                                                  |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SlidingPercentileBandwidthStatistic](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#SlidingPercentileBandwidthStatistic())`()` Creates an instance with a maximum of[DEFAULT_MAX_SAMPLES_COUNT](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#DEFAULT_MAX_SAMPLES_COUNT())samples, returning the[DEFAULT_PERCENTILE](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#DEFAULT_PERCENTILE()). |
| [SlidingPercentileBandwidthStatistic](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#SlidingPercentileBandwidthStatistic(int,double))`(` ` maxSampleCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` percentile: `[Double](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html) `)` Creates an instance.                                                                                                                                                                                                 |

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [addSample](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#addSample(long,long))`(bytes: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`, durationUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Adds a transfer sample to the statistic.                                                  |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | [getBandwidthEstimate](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#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) | [reset](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#reset())`()` Resets the statistic.                                                                                                                                                                                                                                                                         |

## Constants

### DEFAULT_MAX_SAMPLES_COUNT

```
const val DEFAULT_MAX_SAMPLES_COUNT = 10: Int
```

The default maximum number of samples.  

### DEFAULT_PERCENTILE

```
const val DEFAULT_PERCENTILE = 0.5: Double
```

The default percentile to return.  

## Public constructors

### SlidingPercentileBandwidthStatistic

```
SlidingPercentileBandwidthStatistic()
```

Creates an instance with a maximum of[DEFAULT_MAX_SAMPLES_COUNT](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#DEFAULT_MAX_SAMPLES_COUNT())samples, returning the[DEFAULT_PERCENTILE](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#DEFAULT_PERCENTILE()).  

### SlidingPercentileBandwidthStatistic

```
SlidingPercentileBandwidthStatistic(
    maxSampleCount: Int,
    percentile: Double
)
```

Creates an instance.  

|                                           Parameters                                            |
|-------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| `maxSampleCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)   | The maximum number of samples.                             |
| `percentile: `[Double](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html) | The percentile to return. Must be in the range of \[0-1\]. |

## Public functions

### addSample

```
fun addSample(bytes: Long, durationUs: Long): Unit
```

Adds a transfer sample to the statistic.  

|                                         Parameters                                          |
|---------------------------------------------------------------------------------------------|------------------------------------------------|
| `bytes: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)      | The number of bytes transferred.               |
| `durationUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The duration of the transfer, in microseconds. |

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

### reset

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

Resets the statistic. The statistic should drop all samples and reset to its initial state, similar to right after construction.