# SpeedProviderUtil

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/common/util/SpeedProviderUtil "View this page in Java")

<br />

```
@UnstableApi
class SpeedProviderUtil
```

<br />

*** ** * ** ***

Utilities for[SpeedProvider](https://developer.android.com/reference/kotlin/androidx/media3/common/audio/SpeedProvider).

## Summary

|                                     ### Public functions                                      |
|-----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)   | [getDurationAfterSpeedProviderApplied](https://developer.android.com/reference/kotlin/androidx/media3/common/util/SpeedProviderUtil#getDurationAfterSpeedProviderApplied(androidx.media3.common.audio.SpeedProvider,long))`(` ` speedProvider: `[SpeedProvider](https://developer.android.com/reference/kotlin/androidx/media3/common/audio/SpeedProvider)`!,` ` durationUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) `)` Returns the duration of the output when the given[SpeedProvider](https://developer.android.com/reference/kotlin/androidx/media3/common/audio/SpeedProvider)is applied given an input stream with the given`durationUs`.                                                  |
| `java-static `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)   | [getNextSpeedChangeSamplePosition](https://developer.android.com/reference/kotlin/androidx/media3/common/util/SpeedProviderUtil#getNextSpeedChangeSamplePosition(androidx.media3.common.audio.SpeedProvider,long,int))`(` ` speedProvider: `[SpeedProvider](https://developer.android.com/reference/kotlin/androidx/media3/common/audio/SpeedProvider)`!,` ` samplePosition: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` sampleRate: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Returns the sample position of the next speed change or[INDEX_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#INDEX_UNSET())if none is set. |
| `java-static `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [getSampleAlignedSpeed](https://developer.android.com/reference/kotlin/androidx/media3/common/util/SpeedProviderUtil#getSampleAlignedSpeed(androidx.media3.common.audio.SpeedProvider,long,int))`(` ` speedProvider: `[SpeedProvider](https://developer.android.com/reference/kotlin/androidx/media3/common/audio/SpeedProvider)`!,` ` samplePosition: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`,` ` sampleRate: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Returns the speed at the specified sample position.                                                                                                                                              |

## Public functions

### getDurationAfterSpeedProviderApplied

```
java-static fun getDurationAfterSpeedProviderApplied(
    speedProvider: SpeedProvider!,
    durationUs: Long
): Long
```

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

### getNextSpeedChangeSamplePosition

```
java-static fun getNextSpeedChangeSamplePosition(
    speedProvider: SpeedProvider!,
    samplePosition: Long,
    sampleRate: Int
): Long
```

Returns the sample position of the next speed change or[INDEX_UNSET](https://developer.android.com/reference/kotlin/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[getSampleAlignedSpeed](https://developer.android.com/reference/kotlin/androidx/media3/common/util/SpeedProviderUtil#getSampleAlignedSpeed(androidx.media3.common.audio.SpeedProvider,long,int)).  

### getSampleAlignedSpeed

```
java-static fun getSampleAlignedSpeed(
    speedProvider: SpeedProvider!,
    samplePosition: Long,
    sampleRate: Int
): Float
```

Returns the speed at the specified sample position.

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