# OggFileAudioBufferSink

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

*** ** * ** ***


```
@UnstableApi
public final class OggFileAudioBufferSink extends ForwardingAudioSink
```

<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.OggFileAudioBufferSink](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. When new audio data is handled after flushing the audio packetizer, a counter is incremented and its value is appended to the output file name.

Note: if writing to external storage it's necessary to grant the `
WRITE_EXTERNAL_STORAGE` permission.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/test/utils/OggFileAudioBufferSink#SAMPLE_RATE() = 48000` Opus streams are always 48000 Hz. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/OggFileAudioBufferSink#OggFileAudioBufferSink(androidx.media3.exoplayer.audio.AudioSink,java.lang.String)( https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink audioSink, https://developer.android.com/reference/java/lang/String.html outputFileNamePrefix )` Creates an instance. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/OggFileAudioBufferSink#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/OggFileAudioBufferSink#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/OggFileAudioBufferSink#reset()()` Resets the sink, releasing any resources that it currently holds. |

### 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) `void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#configure(androidx.media3.exoplayer.audio.AudioSink.AudioSinkConfig)(https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink.AudioSinkConfig audioSinkConfig)`

Configures (or reconfigures) the sink.
`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.
`void` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#handleDiscontinuity()()`

Signals to the sink that the next buffer may be discontinuous with the previous buffer.
`boolean` `https://developer.android.com/reference/androidx/media3/exoplayer/audio/ForwardingAudioSink#hasPendingData()()`

Returns whether the sink has data pending that has not been consumed yet.
`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#pause()()`

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

Starts or resumes consuming audio if initialized.
`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`.

## Constants

### SAMPLE_RATE

```
public static final int SAMPLE_RATE = 48000
```

Opus streams are always 48000 Hz.

## Public constructors

### OggFileAudioBufferSink

```
public OggFileAudioBufferSink(
    AudioSink audioSink,
    String outputFileNamePrefix
)
```

Creates an instance.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/audio/AudioSink audioSink` | The base audioSink calls are forwarded to. |
| `https://developer.android.com/reference/java/lang/String.html outputFileNamePrefix` | The prefix for output files. |

## Public methods

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

### reset

```
public void reset()
```

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