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

*** ** * ** ***


```
@UnstableApi
public class SlidingPercentileBandwidthStatistic implements BandwidthStatistic
```

<br />

*** ** * ** ***

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

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#DEFAULT_MAX_SAMPLES_COUNT() = 10` The default maximum number of samples. |
| `static final double` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#DEFAULT_PERCENTILE() = 0.5` The default percentile to return. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#SlidingPercentileBandwidthStatistic()()` Creates an instance with a maximum of `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#DEFAULT_MAX_SAMPLES_COUNT()` samples, returning the `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#DEFAULT_PERCENTILE()`. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#SlidingPercentileBandwidthStatistic(int,double)( int maxSampleCount, double percentile )` Creates an instance. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#addSample(long,long)(long bytes, long durationUs)` Adds a transfer sample to the statistic. |
| `long` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#getBandwidthEstimate()()` Returns the bandwidth estimate in bits per second, or `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#ESTIMATE_NOT_AVAILABLE()` if there is no estimate available yet. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingPercentileBandwidthStatistic#reset()()` Resets the statistic. |

## Constants

### DEFAULT_MAX_SAMPLES_COUNT

```
public static final int DEFAULT_MAX_SAMPLES_COUNT = 10
```

The default maximum number of samples.

### DEFAULT_PERCENTILE

```
public static final double DEFAULT_PERCENTILE = 0.5
```

The default percentile to return.

## Public constructors

### SlidingPercentileBandwidthStatistic

```
public SlidingPercentileBandwidthStatistic()
```

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

### SlidingPercentileBandwidthStatistic

```
public SlidingPercentileBandwidthStatistic(
    int maxSampleCount,
    double percentile
)
```

Creates an instance.

| Parameters |
|---|---|
| `int maxSampleCount` | The maximum number of samples. |
| `double percentile` | The percentile to return. Must be in the range of \[0-1\]. |

## Public methods

### addSample

```
public void addSample(long bytes, long durationUs)
```

Adds a transfer sample to the statistic.

| Parameters |
|---|---|
| `long bytes` | The number of bytes transferred. |
| `long durationUs` | The duration of the transfer, in microseconds. |

### getBandwidthEstimate

```
public long getBandwidthEstimate()
```

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

### reset

```
public void reset()
```

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