# AudioSink

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

*** ** * ** ***


```
@UnstableApi
public interface AudioSink
```

<br />

Known direct subclasses [DefaultAudioSink](https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioSink), [ForwardingAudioSink](https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink)

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioSink` | Plays audio data. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink` | An overridable `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink` implementation forwarding all methods to another sink. |

Known indirect subclasses [CapturingAudioSink](https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink), [OggFileAudioBufferSink](https://developer.android.com/reference/androidx/media3/test/utils/OggFileAudioBufferSink)

|---|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink` | An `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink` forwarding to `https://developer.android.com/reference/androidx/media3/exoplayer/audio/DefaultAudioSink` that captures configuration, discontinuity and buffer events. |
| `https://developer.android.com/reference/androidx/media3/test/utils/OggFileAudioBufferSink` | A sink for audio buffers that writes output audio as .ogg files with a given path prefix. |

*** ** * ** ***

A sink that consumes audio data.

Before starting playback, specify the input audio format by calling `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#configure(androidx.media3.exoplayer.audio.AudioSink.AudioSinkConfig)`.

Call `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#handleBuffer(java.nio.ByteBuffer,long,int)` to write data, and `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#handleDiscontinuity()` when the data being fed is discontinuous. Call `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#play()` to start playing the written data.

Call `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#configure(androidx.media3.exoplayer.audio.AudioSink.AudioSinkConfig)` whenever the input format changes. The sink will be reinitialized on the next call to `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#handleBuffer(java.nio.ByteBuffer,long,int)`.

Call `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#flush()` to prepare the sink to receive audio data from a new playback position.

Call `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#playToEndOfStream()` repeatedly to play out all data when no more input buffers will be provided via `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#handleBuffer(java.nio.ByteBuffer,long,int)` until the next `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#flush()`. Call `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#reset()` when the instance is no longer required.

The implementation may be backed by a platform `https://developer.android.com/reference/android/media/AudioTrack.html`. In this case, `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setAudioSessionId(int)`, `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setAudioAttributes(androidx.media3.common.AudioAttributes)`, `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#enableTunnelingV21()` and `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#disableTunneling()` may be called before writing data to the sink. These methods may also be called after writing data to the sink, in which case it will be reinitialized as required. For implementations that are not based on platform `https://developer.android.com/reference/android/media/AudioTrack.html`s, calling methods relating to audio sessions, audio attributes, and tunneling may have no effect.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.AudioSinkConfig` Configuration parameters for `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#configure(androidx.media3.exoplayer.audio.AudioSink.AudioSinkConfig)` the audio sink. |
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.AudioSinkConfig.Builder` Builder for `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.AudioSinkConfig`. |
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.AudioTrackConfig` Configuration parameters used for an `https://developer.android.com/reference/android/media/AudioTrack.html`. |
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.ConfigurationException extends https://developer.android.com/reference/java/lang/Exception.html` Thrown when a failure occurs configuring the sink. |
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.InitializationException extends https://developer.android.com/reference/java/lang/Exception.html` Thrown when a failure occurs initializing the sink. |
| `public interface https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.Listener` Listener for audio sink events. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.OffloadMode` Audio offload mode configuration. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.SinkFormatSupport` The level of support the sink provides for a format. |
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.UnexpectedDiscontinuityException extends https://developer.android.com/reference/java/lang/Exception.html` Thrown when the sink encounters an unexpected timestamp discontinuity. |
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.WriteException extends https://developer.android.com/reference/java/lang/Exception.html` Thrown when a failure occurs writing to the sink. |

| ### Constants |
|---|---|
| `default static final long` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#CURRENT_POSITION_NOT_SET() = -9223372036854775808` Returned by `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#getCurrentPositionUs(boolean)` when the position is not set. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#OFFLOAD_MODE_DISABLED() = 0` The audio sink will never play in offload mode. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#OFFLOAD_MODE_ENABLED_GAPLESS_NOT_REQUIRED() = 2` The audio sink will prefer offload playback even if this might result in silence gaps between tracks. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#OFFLOAD_MODE_ENABLED_GAPLESS_REQUIRED() = 1` The audio sink will prefer offload playback except in the case where both the track is gapless and the device does support gapless offload playback. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#SINK_FORMAT_SUPPORTED_DIRECTLY() = 2` The sink supports the format directly, without the need for internal transcoding. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#SINK_FORMAT_SUPPORTED_WITH_TRANSCODING() = 1` The sink supports the format, but needs to transcode it internally to do so. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#SINK_FORMAT_UNSUPPORTED() = 0` The sink does not support the format. |

| ### Public methods |
|---|---|
| `default void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#configure(androidx.media3.exoplayer.audio.AudioSink.AudioSinkConfig)(https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.AudioSinkConfig audioSinkConfig)` Configures (or reconfigures) the sink. |
| `default void` | `[configure](https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#configure(androidx.media3.common.Format,int,int[]))( https://developer.android.com/reference/androidx/media3/common/Format inputFormat, int specifiedBufferSize, @https://developer.android.com/reference/androidx/annotation/Nullable int[] outputChannels )` **This method is deprecated.** Call and implement `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#configure(androidx.media3.exoplayer.audio.AudioSink.AudioSinkConfig)` instead. <br /> |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#disableTunneling()()` Disables tunneling. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#enableTunnelingV21()()` Enables tunneling, if possible. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#flush()()` Flushes the sink, after which it is ready to receive buffers from a new playback position. |
| `abstract @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/AudioAttributes` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#getAudioAttributes()()` Returns the audio attributes used for audio playback, or `null` if the sink does not use audio attributes. |
| `default @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioCapabilities` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#getAudioCapabilities()()` Returns the AudioCapabilities of the sink, if supported by the sink implementation. |
| `abstract long` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#getAudioTrackBufferSizeUs()()` Returns the size of the underlying `https://developer.android.com/reference/android/media/AudioTrack.html` buffer in microseconds. |
| `abstract long` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#getCurrentPositionUs(boolean)(boolean sourceEnded)` Returns the playback position in the stream starting at zero, in microseconds, or `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#CURRENT_POSITION_NOT_SET()` if it is not yet available. |
| `default https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioOffloadSupport` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#getFormatOffloadSupport(androidx.media3.common.Format)(https://developer.android.com/reference/androidx/media3/common/Format format)` Returns the level of offload support that the sink can provide for a given `https://developer.android.com/reference/androidx/media3/common/Format`. |
| `abstract int` | `@https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.SinkFormatSupport https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#getFormatSupport(androidx.media3.common.Format)(https://developer.android.com/reference/androidx/media3/common/Format format)` Returns the level of support that the sink provides for a given `https://developer.android.com/reference/androidx/media3/common/Format`. |
| `abstract https://developer.android.com/reference/androidx/media3/common/PlaybackParameters` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#getPlaybackParameters()()` Returns the active `https://developer.android.com/reference/androidx/media3/common/PlaybackParameters`. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#getSkipSilenceEnabled()()` Returns whether silences are skipped in the audio stream. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#handleBuffer(java.nio.ByteBuffer,long,int)( https://developer.android.com/reference/java/nio/ByteBuffer.html buffer, long presentationTimeUs, int encodedAccessUnitCount )` Attempts to process data from a `https://developer.android.com/reference/java/nio/ByteBuffer.html`, starting from its current position and ending at its limit (exclusive). |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#handleDiscontinuity()()` Signals to the sink that the next buffer may be discontinuous with the previous buffer. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#hasPendingData()()` Returns whether the sink has data pending that has not been consumed yet. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#isEnded()()` Returns whether `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#playToEndOfStream()` has been called and all buffers have been processed. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#pause()()` Pauses playback. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#play()()` Starts or resumes consuming audio if initialized. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#playToEndOfStream()()` Processes any remaining data. |
| `default void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#release()()` Releases the audio sink. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#reset()()` Resets the sink, releasing any resources that it currently holds. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setAudioAttributes(androidx.media3.common.AudioAttributes)(https://developer.android.com/reference/androidx/media3/common/AudioAttributes audioAttributes)` Sets attributes for audio playback. |
| `default void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setAudioOutputProvider(androidx.media3.exoplayer.audio.AudioOutputProvider)(https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioOutputProvider audioOutputProvider)` Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioOutputProvider` to use as the output path. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setAudioSessionId(int)(int audioSessionId)` Sets the audio session id. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setAuxEffectInfo(androidx.media3.common.AuxEffectInfo)(https://developer.android.com/reference/androidx/media3/common/AuxEffectInfo auxEffectInfo)` Sets the auxiliary effect. |
| `default void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setClock(androidx.media3.common.util.Clock)(https://developer.android.com/reference/androidx/media3/common/util/Clock clock)` Sets the `https://developer.android.com/reference/androidx/media3/common/util/Clock` to use for timing in this audio sink. |
| `default void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setEncoderPadding(int)(int paddingInFrames)` Sets the number of audio frames to trim from the end of PCM audio passed to this sink. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setListener(androidx.media3.exoplayer.audio.AudioSink.Listener)(https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.Listener listener)` Sets the listener for sink events, which should be the audio renderer. |
| `default void` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 29) https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setOffloadDelayPadding(int,int)(int delayInFrames, int paddingInFrames)` Sets offload delay and padding on the `https://developer.android.com/reference/android/media/AudioTrack.html`, if possible. |
| `default void` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 29) https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setOffloadMode(int)(@https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.OffloadMode int offloadMode)` Sets audio offload mode, if possible. |
| `default void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setOutputStreamOffsetUs(long)(long outputStreamOffsetUs)` Sets the offset that is added to the media timestamp before it is passed as ` presentationTimeUs` in `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#handleBuffer(java.nio.ByteBuffer,long,int)`. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setPlaybackParameters(androidx.media3.common.PlaybackParameters)(https://developer.android.com/reference/androidx/media3/common/PlaybackParameters playbackParameters)` Attempts to set the playback parameters. |
| `default void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setPlayerId(androidx.media3.exoplayer.analytics.PlayerId)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId playerId)` Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId` of the player using this audio sink. |
| `default void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setPreferredDevice(android.media.AudioDeviceInfo)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/media/AudioDeviceInfo.html audioDeviceInfo)` Sets the preferred audio device. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setSkipSilenceEnabled(boolean)(boolean skipSilenceEnabled)` Sets whether silences should be skipped in the audio stream. |
| `default void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setVirtualDeviceId(int)(int virtualDeviceId)` Sets the virtual device id. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#setVolume(float)(float volume)` Sets the playback volume. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#supportsFormat(androidx.media3.common.Format)(https://developer.android.com/reference/androidx/media3/common/Format format)` Returns whether the sink supports a given `https://developer.android.com/reference/androidx/media3/common/Format`. |

## Constants

### CURRENT_POSITION_NOT_SET

```
default static final long CURRENT_POSITION_NOT_SET = -9223372036854775808
```

Returned by `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#getCurrentPositionUs(boolean)` when the position is not set.

### OFFLOAD_MODE_DISABLED

```
default static final int OFFLOAD_MODE_DISABLED = 0
```

The audio sink will never play in offload mode.

### OFFLOAD_MODE_ENABLED_GAPLESS_NOT_REQUIRED

```
default static final int OFFLOAD_MODE_ENABLED_GAPLESS_NOT_REQUIRED = 2
```

The audio sink will prefer offload playback even if this might result in silence gaps between tracks.

Use this option to prioritize battery saving at the cost of a possible non seamless transitions between tracks of the same album.

### OFFLOAD_MODE_ENABLED_GAPLESS_REQUIRED

```
default static final int OFFLOAD_MODE_ENABLED_GAPLESS_REQUIRED = 1
```

The audio sink will prefer offload playback except in the case where both the track is gapless and the device does support gapless offload playback.

Use this option to prioritize uninterrupted playback of consecutive audio tracks over power savings.

### SINK_FORMAT_SUPPORTED_DIRECTLY

```
default static final int SINK_FORMAT_SUPPORTED_DIRECTLY = 2
```

The sink supports the format directly, without the need for internal transcoding.

### SINK_FORMAT_SUPPORTED_WITH_TRANSCODING

```
default static final int SINK_FORMAT_SUPPORTED_WITH_TRANSCODING = 1
```

The sink supports the format, but needs to transcode it internally to do so. Internal transcoding may result in lower quality and higher CPU load in some cases.

### SINK_FORMAT_UNSUPPORTED

```
default static final int SINK_FORMAT_UNSUPPORTED = 0
```

The sink does not support the format.

## Public methods

### configure

```
default void configure(AudioSink.AudioSinkConfig audioSinkConfig)
```

Configures (or reconfigures) the sink.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.AudioSinkConfig audioSinkConfig` | The `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.AudioSinkConfig`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.ConfigurationException` | If an error occurs configuring the sink. |

### configure

```
default void [configure](https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#configure(androidx.media3.common.Format,int,int[]))(
    Format inputFormat,
    int specifiedBufferSize,
    @Nullable int[] outputChannels
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Call and implement `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#configure(androidx.media3.exoplayer.audio.AudioSink.AudioSinkConfig)` instead.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.ConfigurationException` |   |

### disableTunneling

```
abstract void disableTunneling()
```

Disables tunneling. If tunneling was previously enabled then the sink is reset and any audio session id is cleared.

### enableTunnelingV21

```
abstract void enableTunnelingV21()
```

Enables tunneling, if possible. The sink is reset if tunneling was previously disabled. Enabling tunneling is only possible if the sink is based on a platform `https://developer.android.com/reference/android/media/AudioTrack.html`.

### flush

```
abstract void flush()
```

Flushes the sink, after which it is ready to receive buffers from a new playback position.

The audio session may remain active until `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#reset()` is called.

### getAudioAttributes

```
abstract @Nullable AudioAttributes getAudioAttributes()
```

Returns the audio attributes used for audio playback, or `null` if the sink does not use audio attributes.

### getAudioCapabilities

```
default @Nullable AudioCapabilities getAudioCapabilities()
```

Returns the AudioCapabilities of the sink, if supported by the sink implementation.

### getAudioTrackBufferSizeUs

```
abstract long getAudioTrackBufferSizeUs()
```

Returns the size of the underlying `https://developer.android.com/reference/android/media/AudioTrack.html` buffer in microseconds. If unsupported or the `https://developer.android.com/reference/android/media/AudioTrack.html` is not initialized then return `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()`.

If the `https://developer.android.com/reference/android/media/AudioTrack.html` is configured with a compressed encoding, then the returned duration is an estimated minimum based on the encoding's maximum encoded byte rate.

### getCurrentPositionUs

```
abstract long getCurrentPositionUs(boolean sourceEnded)
```

Returns the playback position in the stream starting at zero, in microseconds, or `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#CURRENT_POSITION_NOT_SET()` if it is not yet available.

| Parameters |
|---|---|
| `boolean sourceEnded` | Specify `true` if no more input buffers will be provided. |

| Returns |
|---|---|
| `long` | The playback position relative to the start of playback, in microseconds. |

### getFormatOffloadSupport

```
default AudioOffloadSupport getFormatOffloadSupport(Format format)
```

Returns the level of offload support that the sink can provide for a given `https://developer.android.com/reference/androidx/media3/common/Format`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The format. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioOffloadSupport` | The level of support provided. |

### getFormatSupport

```
@AudioSink.SinkFormatSupport
abstract int getFormatSupport(Format format)
```

Returns the level of support that the sink provides for a given `https://developer.android.com/reference/androidx/media3/common/Format`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The format. |

| Returns |
|---|---|
| `int` | The level of support provided. |

### getPlaybackParameters

```
abstract PlaybackParameters getPlaybackParameters()
```

Returns the active `https://developer.android.com/reference/androidx/media3/common/PlaybackParameters`.

### getSkipSilenceEnabled

```
abstract boolean getSkipSilenceEnabled()
```

Returns whether silences are skipped in the audio stream.

### handleBuffer

```
abstract boolean handleBuffer(
    ByteBuffer buffer,
    long presentationTimeUs,
    int encodedAccessUnitCount
)
```

Attempts to process data from a `https://developer.android.com/reference/java/nio/ByteBuffer.html`, starting from its current position and ending at its limit (exclusive). The position of the `https://developer.android.com/reference/java/nio/ByteBuffer.html` is advanced by the number of bytes that were handled. `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.Listener#onPositionDiscontinuity()` will be called if `presentationTimeUs` is discontinuous with the last buffer handled since the last reset.

Returns whether the data was handled in full. If the data was not handled in full then the same `https://developer.android.com/reference/java/nio/ByteBuffer.html` must be provided to subsequent calls until it has been fully consumed, except in the case of an intervening call to `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#flush()` (or to `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#configure(androidx.media3.exoplayer.audio.AudioSink.AudioSinkConfig)` that causes the sink to be flushed).

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer.html buffer` | The buffer containing audio data. |
| `long presentationTimeUs` | The presentation timestamp of the buffer in microseconds. |
| `int encodedAccessUnitCount` | The number of encoded access units in the buffer, or 1 if the buffer contains PCM audio. This allows batching multiple encoded access units in one buffer. |

| Returns |
|---|---|
| `boolean` | Whether the buffer was handled fully. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.InitializationException` | If an error occurs initializing the sink. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.WriteException` | If an error occurs writing the audio data. |

### handleDiscontinuity

```
abstract void handleDiscontinuity()
```

Signals to the sink that the next buffer may be discontinuous with the previous buffer.

### hasPendingData

```
abstract boolean hasPendingData()
```

Returns whether the sink has data pending that has not been consumed yet.

### isEnded

```
abstract boolean isEnded()
```

Returns whether `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#playToEndOfStream()` has been called and all buffers have been processed.

### pause

```
abstract void pause()
```

Pauses playback.

### play

```
abstract void play()
```

Starts or resumes consuming audio if initialized.

### playToEndOfStream

```
abstract void playToEndOfStream()
```

Processes any remaining data. `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#isEnded()` will return `true` when no data remains.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.WriteException` | If an error occurs draining data to the sink. |

### release

```
default void release()
```

Releases the audio sink.

### reset

```
abstract void reset()
```

Resets the sink, releasing any resources that it currently holds.

### setAudioAttributes

```
abstract void setAudioAttributes(AudioAttributes audioAttributes)
```

Sets attributes for audio playback. If the attributes have changed and if the sink is not configured for use with tunneling, then it is reset and the audio session id is cleared.

If the sink is configured for use with tunneling then the audio attributes are ignored. The sink is not reset and the audio session id is not cleared. The passed attributes will be used if the sink is later re-configured into non-tunneled mode.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/AudioAttributes audioAttributes` | The attributes for audio playback. |

### setAudioOutputProvider

```
default void setAudioOutputProvider(AudioOutputProvider audioOutputProvider)
```

Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioOutputProvider` to use as the output path.

### setAudioSessionId

```
abstract void setAudioSessionId(int audioSessionId)
```

Sets the audio session id.

### setAuxEffectInfo

```
abstract void setAuxEffectInfo(AuxEffectInfo auxEffectInfo)
```

Sets the auxiliary effect.

### setClock

```
default void setClock(Clock clock)
```

Sets the `https://developer.android.com/reference/androidx/media3/common/util/Clock` to use for timing in this audio sink.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/Clock clock` | The `https://developer.android.com/reference/androidx/media3/common/util/Clock`. |

### setEncoderPadding

```
default void setEncoderPadding(int paddingInFrames)
```

Sets the number of audio frames to trim from the end of PCM audio passed to this sink.

Applies to the most recently `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#configure(androidx.media3.exoplayer.audio.AudioSink.AudioSinkConfig)` input if it is PCM, and overrides any padding configured via the `https://developer.android.com/reference/androidx/media3/common/Format`. Reset to the configured value on `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#flush()`.

| Parameters |
|---|---|
| `int paddingInFrames` | The number of audio frames to trim from the end of audio. Must be non-negative. |

### setListener

```
abstract void setListener(AudioSink.Listener listener)
```

Sets the listener for sink events, which should be the audio renderer.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.Listener listener` | The listener for sink events, which should be the audio renderer. |

### setOffloadDelayPadding

```
@RequiresApi(value = 29)
default void setOffloadDelayPadding(int delayInFrames, int paddingInFrames)
```

Sets offload delay and padding on the `https://developer.android.com/reference/android/media/AudioTrack.html`, if possible.

Setting the offload delay and padding is only possible if the sink is based on a platform `https://developer.android.com/reference/android/media/AudioTrack.html` in offload mode, and requires platform API version 29 onwards.

Applies to the most recently `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#configure(androidx.media3.exoplayer.audio.AudioSink.AudioSinkConfig)` input if it is not PCM, and overrides any delay and padding configured via the `https://developer.android.com/reference/androidx/media3/common/Format`. Reset to the configured values on `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#flush()`.

| Parameters |
|---|---|
| `int delayInFrames` | The number of audio frames to trim from the start of audio. |
| `int paddingInFrames` | The number of audio frames to trim from the end of audio. |

### setOffloadMode

```
@RequiresApi(value = 29)
default void setOffloadMode(@AudioSink.OffloadMode int offloadMode)
```

Sets audio offload mode, if possible. Enabling offload is only possible if the sink is based on a platform `https://developer.android.com/reference/android/media/AudioTrack.html`, and requires platform API version 29 onwards.

### setOutputStreamOffsetUs

```
default void setOutputStreamOffsetUs(long outputStreamOffsetUs)
```

Sets the offset that is added to the media timestamp before it is passed as `
presentationTimeUs` in `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#handleBuffer(java.nio.ByteBuffer,long,int)`.

| Parameters |
|---|---|
| `long outputStreamOffsetUs` | The output stream offset in microseconds. |

### setPlaybackParameters

```
abstract void setPlaybackParameters(PlaybackParameters playbackParameters)
```

Attempts to set the playback parameters. The audio sink may override these parameters if they are not supported.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/PlaybackParameters playbackParameters` | The new playback parameters to attempt to set. |

### setPlayerId

```
default void setPlayerId(@Nullable PlayerId playerId)
```

Sets the `https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId` of the player using this audio sink.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId playerId` | The `https://developer.android.com/reference/androidx/media3/exoplayer/analytics/PlayerId`, or null to clear a previously set id. |

### setPreferredDevice

```
default void setPreferredDevice(@Nullable AudioDeviceInfo audioDeviceInfo)
```

Sets the preferred audio device.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/media/AudioDeviceInfo.html audioDeviceInfo` | The preferred `https://developer.android.com/reference/android/media/AudioDeviceInfo.html`, or null to restore the default. |

### setSkipSilenceEnabled

```
abstract void setSkipSilenceEnabled(boolean skipSilenceEnabled)
```

Sets whether silences should be skipped in the audio stream.

### setVirtualDeviceId

```
default void setVirtualDeviceId(int virtualDeviceId)
```

Sets the virtual device id.

| Parameters |
|---|---|
| `int virtualDeviceId` | The `https://developer.android.com/reference/android/companion/virtual/VirtualDevice.html#getDeviceId()`, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if unspecified. |

### setVolume

```
abstract void setVolume(float volume)
```

Sets the playback volume.

| Parameters |
|---|---|
| `float volume` | Linear output gain to apply to all channels. Should be in the range \[0.0, 1.0\]. |

### supportsFormat

```
abstract boolean supportsFormat(Format format)
```

Returns whether the sink supports a given `https://developer.android.com/reference/androidx/media3/common/Format`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The format. |

| Returns |
|---|---|
| `boolean` | Whether the sink supports the format. |