OggFileAudioBufferSink
@UnstableApi
public final class OggFileAudioBufferSink extends ForwardingAudioSink
| java.lang.Object | ||
| ↳ | androidx.media3.exoplayer.audio.ForwardingAudioSink | |
| ↳ | 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 |
SAMPLE_RATE = 48000Opus streams are always 48000 Hz. |
Public constructors |
|---|
OggFileAudioBufferSink(Creates an instance. |
Public methods |
|
|---|---|
void |
flush()Flushes the sink, after which it is ready to receive buffers from a new playback position. |
boolean |
handleBuffer(Attempts to process data from a |
void |
reset()Resets the sink, releasing any resources that it currently holds. |
Inherited Constants |
||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
Public constructors
OggFileAudioBufferSink
public OggFileAudioBufferSink(
AudioSink audioSink,
String outputFileNamePrefix
)
Creates an instance.
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 reset is called.
handleBuffer
public boolean handleBuffer(
ByteBuffer buffer,
long presentationTimeUs,
int encodedAccessUnitCount
)
Attempts to process data from a ByteBuffer, starting from its current position and ending at its limit (exclusive). The position of the ByteBuffer is advanced by the number of bytes that were handled. 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 ByteBuffer must be provided to subsequent calls until it has been fully consumed, except in the case of an intervening call to flush (or to configure that causes the sink to be flushed).
| Parameters | |
|---|---|
ByteBuffer 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 | |
|---|---|
androidx.media3.exoplayer.audio.AudioSink.InitializationException |
If an error occurs initializing the sink. |
androidx.media3.exoplayer.audio.AudioSink.WriteException |
If an error occurs writing the audio data. |