# SpeedProviderUtil

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

*** ** * ** ***


```
@UnstableApi
public class SpeedProviderUtil
```

<br />

*** ** * ** ***

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

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/common/util/SpeedProviderUtil.SpeedProviderMapper` Class that maps timestamps between original media time and adjusted time after applying a `https://developer.android.com/reference/androidx/media3/common/audio/SpeedProvider`. |

| ### Public methods |
|---|---|
| `static long` | `https://developer.android.com/reference/androidx/media3/common/util/SpeedProviderUtil#getDurationAfterSpeedProviderApplied(androidx.media3.common.audio.SpeedProvider,long)( https://developer.android.com/reference/androidx/media3/common/audio/SpeedProvider speedProvider, long durationUs )` Returns the duration of the output when the given `https://developer.android.com/reference/androidx/media3/common/audio/SpeedProvider` is applied given an input stream with the given `durationUs`. |
| `static long` | `https://developer.android.com/reference/androidx/media3/common/util/SpeedProviderUtil#getNextSpeedChangeSamplePosition(androidx.media3.common.audio.SpeedProvider,long,int)( https://developer.android.com/reference/androidx/media3/common/audio/SpeedProvider speedProvider, long samplePosition, int sampleRate )` Returns the sample position of the next speed change or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if none is set. |
| `static float` | `https://developer.android.com/reference/androidx/media3/common/util/SpeedProviderUtil#getSampleAlignedSpeed(androidx.media3.common.audio.SpeedProvider,long,int)( https://developer.android.com/reference/androidx/media3/common/audio/SpeedProvider speedProvider, long samplePosition, int sampleRate )` Returns the speed at the specified sample position. |

## Public methods

### getDurationAfterSpeedProviderApplied

```
public static long getDurationAfterSpeedProviderApplied(
    SpeedProvider speedProvider,
    long durationUs
)
```

Returns the duration of the output when the given `https://developer.android.com/reference/androidx/media3/common/audio/SpeedProvider` is applied given an input stream with the given `durationUs`.

### getNextSpeedChangeSamplePosition

```
public static long getNextSpeedChangeSamplePosition(
    SpeedProvider speedProvider,
    long samplePosition,
    int sampleRate
)
```

Returns the sample position of the next speed change or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if none is set.

If the next speed change falls between sample boundaries, this method will return the next closest sample position, which ensures that speed regions stay consistent with `https://developer.android.com/reference/androidx/media3/common/util/SpeedProviderUtil#getSampleAlignedSpeed(androidx.media3.common.audio.SpeedProvider,long,int)`.

### getSampleAlignedSpeed

```
public static float getSampleAlignedSpeed(
    SpeedProvider speedProvider,
    long samplePosition,
    int sampleRate
)
```

Returns the speed at the specified sample position.

This method is consistent with the alignment done by `https://developer.android.com/reference/androidx/media3/common/util/SpeedProviderUtil#getNextSpeedChangeSamplePosition(androidx.media3.common.audio.SpeedProvider,long,int)`.