# CapturingAudioSink

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/CapturingAudioSink.java+class:androidx.media3.test.utils.CapturingAudioSink)

*** ** * ** ***


```
@UnstableApi
public class CapturingAudioSink extends ForwardingAudioSink implements Dumper.Dumpable
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.media3.exoplayer.audio.ForwardingAudioSink](https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink) ||
|   | ↳ | [androidx.media3.test.utils.CapturingAudioSink](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.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink.InterceptingBufferSink implements https://developer.android.com/reference/androidx/media3/exoplayer/audio/TeeAudioProcessor.AudioBufferSink` |
| `public final class https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink.SampleInterceptingBufferSink implements https://developer.android.com/reference/androidx/media3/exoplayer/audio/TeeAudioProcessor.AudioBufferSink` |

| ### Protected constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink#CapturingAudioSink(androidx.media3.exoplayer.audio.AudioSink,boolean)( https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink sink, boolean shouldCaptureIndividualBuffers )` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink#configure(androidx.media3.exoplayer.audio.AudioSink.AudioSinkConfig)(https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.AudioSinkConfig audioSinkConfig)` Configures (or reconfigures) the sink. |
| `static https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink` | `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink#create()()` Creates the capturing audio sink. |
| `static https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink` | `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink#createForSampleCapturing()()` |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink#dump(androidx.media3.test.utils.Dumper)(https://developer.android.com/reference/androidx/media3/test/utils/Dumper dumper)` Dumps the fields of the object using the `dumper`. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink#flush()()` Flushes the sink, after which it is ready to receive buffers from a new playback position. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink#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). |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink#handleDiscontinuity()()` Signals to the sink that the next buffer may be discontinuous with the previous buffer. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink#hasPendingData()()` Returns whether the sink has data pending that has not been consumed yet. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink#pause()()` Pauses playback. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink#play()()` Starts or resumes consuming audio if initialized. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink#reset()()` Resets the sink, releasing any resources that it currently holds. |

| ### Protected methods |
|---|---|
| `final https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink` | `https://developer.android.com/reference/androidx/media3/test/utils/CapturingAudioSink#getDelegateAudioSink()()` Returns the wrapped `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink`. |

### Inherited Constants

From [androidx.media3.exoplayer.audio.AudioSink](https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink) `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.
`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.
`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.
`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.
`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.
`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.
`static final int` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink#SINK_FORMAT_UNSUPPORTED() = 0`

The sink does not support the format.

### Inherited methods

From [androidx.media3.exoplayer.audio.AudioSink](https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink) `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).
From [androidx.media3.exoplayer.audio.ForwardingAudioSink](https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink) `final void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#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 />

`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#disableTunneling()()`

Disables tunneling.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#enableTunnelingV21()()`

Enables tunneling, if possible.
`@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/ForwardingAudioSink#getAudioAttributes()()`

Returns the audio attributes used for audio playback, or `null` if the sink does not use audio attributes.
`@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/ForwardingAudioSink#getAudioCapabilities()()`

Returns the AudioCapabilities of the sink, if supported by the sink implementation.
`long` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#getAudioTrackBufferSizeUs()()`

Returns the size of the underlying `https://developer.android.com/reference/android/media/AudioTrack.html` buffer in microseconds.
`long` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#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.
`https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioOffloadSupport` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#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`.
`int` `@https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.SinkFormatSupport
https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#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`.
`https://developer.android.com/reference/androidx/media3/common/PlaybackParameters` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#getPlaybackParameters()()`

Returns the active `https://developer.android.com/reference/androidx/media3/common/PlaybackParameters`.
`boolean` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#getSkipSilenceEnabled()()`

Returns whether silences are skipped in the audio stream.
`boolean` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#isEnded()()`

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

Processes any remaining data.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#release()()`

Releases the audio sink.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#setAudioAttributes(androidx.media3.common.AudioAttributes)(https://developer.android.com/reference/androidx/media3/common/AudioAttributes audioAttributes)`

Sets attributes for audio playback.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#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.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#setAudioSessionId(int)(int audioSessionId)`

Sets the audio session id.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#setAuxEffectInfo(androidx.media3.common.AuxEffectInfo)(https://developer.android.com/reference/androidx/media3/common/AuxEffectInfo auxEffectInfo)`

Sets the auxiliary effect.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#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.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#setEncoderPadding(int)(int paddingInFrames)`

Sets the number of audio frames to trim from the end of PCM audio passed to this sink.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#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.
`void` `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 29)
https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#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.
`void` `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 29)
https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#setOffloadMode(int)(@https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.OffloadMode int offloadMode)`

Sets audio offload mode, if possible.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#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)`.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#setPlaybackParameters(androidx.media3.common.PlaybackParameters)(https://developer.android.com/reference/androidx/media3/common/PlaybackParameters playbackParameters)`

Attempts to set the playback parameters.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#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.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#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.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#setSkipSilenceEnabled(boolean)(boolean skipSilenceEnabled)`

Sets whether silences should be skipped in the audio stream.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#setVirtualDeviceId(int)(int virtualDeviceId)`

Sets the virtual device id.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#setVolume(float)(float volume)`

Sets the playback volume.
`boolean` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#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`.

## Protected constructors

### CapturingAudioSink

```
protected CapturingAudioSink(
    AudioSink sink,
    boolean shouldCaptureIndividualBuffers
)
```

## Public methods

### configure

```
public 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. |

### create

```
public static CapturingAudioSink create()
```

Creates the capturing audio sink.

### createForSampleCapturing

```
public static CapturingAudioSink createForSampleCapturing()
```

### dump

```
public void dump(Dumper dumper)
```

Dumps the fields of the object using the `dumper`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/Dumper dumper` | The `https://developer.android.com/reference/androidx/media3/test/utils/Dumper` to be used to dump fields. |

### flush

```
public 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.

### handleBuffer

```
public 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

```
public void handleDiscontinuity()
```

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

### hasPendingData

```
public boolean hasPendingData()
```

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

### pause

```
public void pause()
```

Pauses playback.

### play

```
public void play()
```

Starts or resumes consuming audio if initialized.

### reset

```
public void reset()
```

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

## Protected methods

### getDelegateAudioSink

```
protected final AudioSink getDelegateAudioSink()
```

Returns the wrapped `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink`.