# AudioTrackAudioOutput

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/audio/AudioTrackAudioOutput.java+class:androidx.media3.exoplayer.audio.AudioTrackAudioOutput)

*** ** * ** ***


```
class AudioTrackAudioOutput : AudioOutput
```

<br />

*** ** * ** ***

A default implementation of `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput` that wraps an `https://developer.android.com/reference/android/media/AudioTrack.html`.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi interface https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput.CapabilityChangeListener` Listener for potential capability change events. |
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi class https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput.InvalidAudioTrackTimestampException : https://developer.android.com/reference/java/lang/RuntimeException.html` Thrown when the audio track has provided a spurious timestamp, if `https://developer.android.com/reference/kotlin/androidx/media3/common/MediaLibraryInfo#enableWorkarounds()` is false. |

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi [AudioTrackAudioOutput](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#AudioTrackAudioOutput(android.media.AudioTrack,androidx.media3.exoplayer.audio.AudioOutputProvider.OutputConfig,androidx.media3.exoplayer.audio.AudioTrackAudioOutput.CapabilityChangeListener,androidx.media3.common.util.Clock))( audioTrack: https://developer.android.com/reference/android/media/AudioTrack.html!, config: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutputProvider.OutputConfig!, capabilityChangeListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput.CapabilityChangeListener?, clock: https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock! )` **This function is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#AudioTrackAudioOutput(android.media.AudioTrack,androidx.media3.exoplayer.audio.AudioOutputProvider.OutputConfig,androidx.media3.exoplayer.audio.AudioTrackAudioOutput.CapabilityChangeListener,float,androidx.media3.common.util.Clock)` instead. <br /> |
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#AudioTrackAudioOutput(android.media.AudioTrack,androidx.media3.exoplayer.audio.AudioOutputProvider.OutputConfig,androidx.media3.exoplayer.audio.AudioTrackAudioOutput.CapabilityChangeListener,float,androidx.media3.common.util.Clock)( audioTrack: https://developer.android.com/reference/android/media/AudioTrack.html!, config: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutputProvider.OutputConfig!, capabilityChangeListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput.CapabilityChangeListener?, maxPlaybackSpeed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, clock: https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock! )` Creates a new instance. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#addListener(androidx.media3.exoplayer.audio.AudioOutput.Listener)(listener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput.Listener!)` Adds a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput.Listener` for audio output events. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#attachAuxEffect(int)(effectId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Attaches an auxiliary effect to the output. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#flush()()` Flushes the audio data from the output. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#getAudioSessionId()()` Returns the audio session ID or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#AUDIO_SESSION_ID_UNSET()` if unknown. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#getBufferSizeInFrames()()` Returns the buffer size in frames of the underlying `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackParameters!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#getPlaybackParameters()()` Returns the playback parameters. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#getPositionUs()()` Returns the current playout timestamp in microseconds. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#getSampleRate()()` Returns the sample rate of the underlying `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#isOffloadedPlayback()()` Returns whether this output is playing back in offload mode. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#isStalled()()` Returns whether the audio output is stalled. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#pause()()` Pauses playback. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#play()()` Starts or resumes playing audio. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#release()()` Releases the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#removeListener(androidx.media3.exoplayer.audio.AudioOutput.Listener)(listener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput.Listener!)` Removes a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput.Listener` for audio output events. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#setAuxEffectSendLevel(float)(level: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Sets the send level for the auxiliary effect. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#setOffloadDelayPadding(int,int)(delayInFrames: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, paddingInFrames: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the offload delay and padding. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#setOffloadEndOfStream()()` Notifies the output that this is the end of the stream. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#setPlaybackParameters(androidx.media3.common.PlaybackParameters)(playbackParameters: https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackParameters!)` Sets the playback parameters. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#setPlayerId(androidx.media3.exoplayer.analytics.PlayerId)(playerId: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/analytics/PlayerId!)` Sets the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/analytics/PlayerId` on the audio output. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#setPreferredDevice(android.media.AudioDeviceInfo)(preferredDevice: https://developer.android.com/reference/android/media/AudioDeviceInfo.html?)` Sets the preferred audio device for routing, or null for no preference. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#setVolume(float)(volume: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Sets the volume of the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#stop()()` Signal that the last buffer has been written and playback should stop after playing out all remaining buffers |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#write(java.nio.ByteBuffer,int,long)( buffer: https://developer.android.com/reference/java/nio/ByteBuffer.html!, encodedAccessUnitCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html )` Writes audio data to the audio output for playback with a presentation timestamp. |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/android/media/AudioTrack.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#audioTrack()` |

| ### Inherited functions |
|---|
| From [androidx.media3.exoplayer.audio.AudioOutput](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput) |---|---| | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput#canReuseAudioOutput(androidx.media3.exoplayer.audio.AudioOutputProvider.OutputConfig,androidx.media3.exoplayer.audio.AudioOutputProvider.FormatConfig,androidx.media3.exoplayer.audio.AudioOutputProvider.OutputConfig)( currentConfig: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutputProvider.OutputConfig!, newFormat: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutputProvider.FormatConfig!, newConfig: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutputProvider.OutputConfig! )` Returns if the configurations are sufficiently compatible to reuse this audio output. | |

## Public constructors

### AudioTrackAudioOutput

```
@UnstableApi
[AudioTrackAudioOutput](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#AudioTrackAudioOutput(android.media.AudioTrack,androidx.media3.exoplayer.audio.AudioOutputProvider.OutputConfig,androidx.media3.exoplayer.audio.AudioTrackAudioOutput.CapabilityChangeListener,androidx.media3.common.util.Clock))(
    audioTrack: AudioTrack!,
    config: AudioOutputProvider.OutputConfig!,
    capabilityChangeListener: AudioTrackAudioOutput.CapabilityChangeListener?,
    clock: Clock!
)
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Use `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput#AudioTrackAudioOutput(android.media.AudioTrack,androidx.media3.exoplayer.audio.AudioOutputProvider.OutputConfig,androidx.media3.exoplayer.audio.AudioTrackAudioOutput.CapabilityChangeListener,float,androidx.media3.common.util.Clock)` instead.

### AudioTrackAudioOutput

```
@UnstableApi
AudioTrackAudioOutput(
    audioTrack: AudioTrack!,
    config: AudioOutputProvider.OutputConfig!,
    capabilityChangeListener: AudioTrackAudioOutput.CapabilityChangeListener?,
    maxPlaybackSpeed: Float,
    clock: Clock!
)
```

Creates a new instance.

| Parameters |
|---|---|
| `audioTrack: https://developer.android.com/reference/android/media/AudioTrack.html!` | The audio track to wrap. |
| `config: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutputProvider.OutputConfig!` | The output configuration. |
| `capabilityChangeListener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput.CapabilityChangeListener?` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioTrackAudioOutput.CapabilityChangeListener`. |
| `maxPlaybackSpeed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The maximum playback speed set on the track if `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutputProvider.OutputConfig#usePlaybackParameters()` is enabled. |
| `clock: https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock`. |

## Public functions

### addListener

```
fun addListener(listener: AudioOutput.Listener!): Unit
```

Adds a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput.Listener` for audio output events.

### attachAuxEffect

```
fun attachAuxEffect(effectId: Int): Unit
```

Attaches an auxiliary effect to the output.

### flush

```
fun flush(): Unit
```

Flushes the audio data from the output.

### getAudioSessionId

```
fun getAudioSessionId(): Int
```

Returns the audio session ID or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#AUDIO_SESSION_ID_UNSET()` if unknown.

### getBufferSizeInFrames

```
fun getBufferSizeInFrames(): Long
```

Returns the buffer size in frames of the underlying `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput`.

### getPlaybackParameters

```
fun getPlaybackParameters(): PlaybackParameters!
```

Returns the playback parameters.

### getPositionUs

```
fun getPositionUs(): Long
```

Returns the current playout timestamp in microseconds.

### getSampleRate

```
fun getSampleRate(): Int
```

Returns the sample rate of the underlying `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput`.

### isOffloadedPlayback

```
fun isOffloadedPlayback(): Boolean
```

Returns whether this output is playing back in offload mode.

### isStalled

```
fun isStalled(): Boolean
```

Returns whether the audio output is stalled.

### pause

```
fun pause(): Unit
```

Pauses playback.

### play

```
fun play(): Unit
```

Starts or resumes playing audio.

### release

```
fun release(): Unit
```

Releases the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput`.

### removeListener

```
fun removeListener(listener: AudioOutput.Listener!): Unit
```

Removes a `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput.Listener` for audio output events.

### setAuxEffectSendLevel

```
fun setAuxEffectSendLevel(level: Float): Unit
```

Sets the send level for the auxiliary effect.

### setOffloadDelayPadding

```
fun setOffloadDelayPadding(delayInFrames: Int, paddingInFrames: Int): Unit
```

Sets the offload delay and padding.

### setOffloadEndOfStream

```
fun setOffloadEndOfStream(): Unit
```

Notifies the output that this is the end of the stream.

### setPlaybackParameters

```
fun setPlaybackParameters(playbackParameters: PlaybackParameters!): Unit
```

Sets the playback parameters.

### setPlayerId

```
@UnstableApi
fun setPlayerId(playerId: PlayerId!): Unit
```

Sets the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/analytics/PlayerId` on the audio output.

### setPreferredDevice

```
fun setPreferredDevice(preferredDevice: AudioDeviceInfo?): Unit
```

Sets the preferred audio device for routing, or null for no preference.

### setVolume

```
fun setVolume(volume: Float): Unit
```

Sets the volume of the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput`.

### stop

```
fun stop(): Unit
```

Signal that the last buffer has been written and playback should stop after playing out all remaining buffers

### write

```
fun write(
    buffer: ByteBuffer!,
    encodedAccessUnitCount: Int,
    presentationTimeUs: Long
): Boolean
```

Writes audio data to the audio output for playback with a presentation timestamp.

The provided `buffer` must be a direct byte buffer with native byte order. The method is read-only and will not modify the bytes. It processes data from `buffer.position()` to `buffer.limit()` (exclusive). Every call will advance `buffer.position()` to reflect the number of bytes written.

The first time this method is called with a new buffer, the buffer must contain one or more complete encoded access units or complete PCM frames.

If this method returns `false`, the same buffer must be used for subsequent calls to this method until it has been fully consumed, or until an intervening call to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput#flush()`.

| Parameters |
|---|---|
| `buffer: https://developer.android.com/reference/java/nio/ByteBuffer.html!` | The buffer containing the audio data. |
| `encodedAccessUnitCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of encoded access units in the buffer when the buffer was first used in this method, or 1 if the buffer contains PCM audio. When calling this method again after it returned `false`, the same number of encoded access units must be provided. |
| `presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The presentation timestamp, in microseconds, of the first access unit or PCM frame when the buffer was first used in this method. When calling this method again after it returned `false`, the same timestamp must be provided. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the buffer was handled fully. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/audio/AudioOutput.WriteException` | If the write fails. The audio output cannot be reused after a failure and needs to be recreated. |

## Public properties

### audioTrack

```
val audioTrack: AudioTrack!
```