# TestSpeedProvider

Artifact: [androidx.media3:media3-test-utils](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/test/utils/TestSpeedProvider.java+class:androidx.media3.test.utils.TestSpeedProvider)

*** ** * ** ***


```
@UnstableApi
public final class TestSpeedProvider implements SpeedProvider
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/androidx/media3/common/audio/SpeedProvider` for tests

## Summary

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/androidx/media3/test/utils/TestSpeedProvider` | `https://developer.android.com/reference/androidx/media3/test/utils/TestSpeedProvider#createWithFrameCounts(androidx.media3.common.audio.AudioProcessor.AudioFormat,int[],float[])( https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat audioFormat, int[] frameCounts, float[] speeds )` Creates a `TestSpeedProvider` instance. |
| `static https://developer.android.com/reference/androidx/media3/test/utils/TestSpeedProvider` | `https://developer.android.com/reference/androidx/media3/test/utils/TestSpeedProvider#createWithStartTimes(long[],float[])(long[] startTimesUs, float[] speeds)` Creates a `TestSpeedProvider` instance. |
| `long` | `https://developer.android.com/reference/androidx/media3/test/utils/TestSpeedProvider#getNextSpeedChangeTimeUs(long)(long timeUs)` Returns the timestamp of the next speed change, if there is any. |
| `float` | `https://developer.android.com/reference/androidx/media3/test/utils/TestSpeedProvider#getSpeed(long)(long timeUs)` Returns the media speed from the provided timestamp. |

| ### Inherited Constants |
|---|
| From [androidx.media3.common.audio.SpeedProvider](https://developer.android.com/reference/androidx/media3/common/audio/SpeedProvider) |---|---| | `static final https://developer.android.com/reference/androidx/media3/common/audio/SpeedProvider` | `https://developer.android.com/reference/androidx/media3/common/audio/SpeedProvider#DEFAULT()` A speed provider with default values. | |

## Public methods

### createWithFrameCounts

```
public static TestSpeedProvider createWithFrameCounts(
    AudioProcessor.AudioFormat audioFormat,
    int[] frameCounts,
    float[] speeds
)
```

Creates a `TestSpeedProvider` instance.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat audioFormat` | the `https://developer.android.com/reference/androidx/media3/common/audio/AudioProcessor.AudioFormat`. |
| `int[] frameCounts` | The frame counts for which the same speed should be applied. |
| `float[] speeds` | The speeds corresponding to each frame count. Consecutive values must be distinct. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/TestSpeedProvider` | A `TestSpeedProvider`. |

### createWithStartTimes

```
public static TestSpeedProvider createWithStartTimes(long[] startTimesUs, float[] speeds)
```

Creates a `TestSpeedProvider` instance.

| Parameters |
|---|---|
| `long[] startTimesUs` | The speed change start times, in microseconds. The values must be distinct and in increasing order. |
| `float[] speeds` | The speeds corresponding to each start time. Consecutive values must be distinct. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/TestSpeedProvider` | A `TestSpeedProvider`. |

### getNextSpeedChangeTimeUs

```
public long getNextSpeedChangeTimeUs(long timeUs)
```

Returns the timestamp of the next speed change, if there is any.

| Parameters |
|---|---|
| `long timeUs` | A timestamp, in microseconds. |

| Returns |
|---|---|
| `long` | The timestamp of the next speed change, in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if there is no next speed change. If `timeUs` corresponds to a speed change, the returned value corresponds to the following speed change. |

### getSpeed

```
public float getSpeed(long timeUs)
```

Returns the media speed from the provided timestamp.

The media speed will stay the same until `https://developer.android.com/reference/androidx/media3/common/audio/SpeedProvider#getNextSpeedChangeTimeUs(long)`.

| Parameters |
|---|---|
| `long timeUs` | The timestamp of the media. |

| Returns |
|---|---|
| `float` | The speed that the media should be played at. |