Interface AudioMixer
-
@Deprecated public interface AudioMixer
Deprecated.com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.An audio component which combines audio data from multiple sources into a single output.The mixer supports an arbitrary number of concurrent sources and will ensure audio data from all sources are aligned and mixed before producing output. Any periods without sources will be filled with silence. The total duration of the mixed track is controlled with
setEndTimeUs(long)
, or is unbounded if left unset.Updates: The mixer supports the following updates at any time without the need for a
reset()
.- Add source. Source audio will be included in future mixed output only.
- Remove source.
- Change source volume. The new volume will apply only to future source samples.
- Change end time. The new end time may cause an immediate change to the mixer ended state.
Changes to the output audio format, buffer size, or mixer start time require the mixer to first be reset, discarding all buffered data.
Operation: The mixer must be configured before any methods are called. Once configured, sources can queue audio data via
queueInput(int, java.nio.ByteBuffer)
and the mixer will consume input audio up to the configured buffer size and end time. Once all sources have produced data for a period thengetOutput()
will return the mixed result. The cycle repeats until the mixerisEnded()
.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description int
addSource(AudioProcessor.AudioFormat sourceFormat, long startTimeUs)
Deprecated.Adds an audio source to mix starting at the given time.void
configure(AudioProcessor.AudioFormat outputAudioFormat, int bufferSizeMs, long startTimeUs)
Deprecated.Configures the mixer.static AudioMixer
create()
Deprecated.Creates an unconfigured instance.ByteBuffer
getOutput()
Deprecated.Returns a buffer containing output audio data between its position and limit.boolean
isEnded()
Deprecated.void
queueInput(int sourceId, ByteBuffer sourceBuffer)
Deprecated.Queues audio data between the position and limit of thesourceBuffer
.void
removeSource(int sourceId)
Deprecated.Removes an audio source.void
reset()
Deprecated.Resets the mixer to its unconfigured state, releasing any resources.void
setEndTimeUs(long endTimeUs)
Deprecated.Sets the end time of the output audio.void
setSourceVolume(int sourceId, float volume)
Deprecated.Sets the volume applied to future samples queued from the given source.boolean
supportsSourceAudioFormat(AudioProcessor.AudioFormat sourceFormat)
Deprecated.Indicates whether the mixer supports mixing sources with the given audio format.
-
-
-
Method Detail
-
create
static AudioMixer create()
Deprecated.Creates an unconfigured instance.
-
configure
void configure(AudioProcessor.AudioFormat outputAudioFormat, int bufferSizeMs, long startTimeUs) throws AudioProcessor.UnhandledAudioFormatException
Deprecated.Configures the mixer.The mixer must be configured before use and can only be reconfigured after a call to
reset()
.The mixing buffer size is set by
bufferSizeMs
and indicates how much audio can be queued beforegetOutput()
is called.- Parameters:
outputAudioFormat
- The audio format of buffers returned fromgetOutput()
.bufferSizeMs
- The mixing buffer size in milliseconds.startTimeUs
- The start time of the mixer output in microseconds.- Throws:
AudioProcessor.UnhandledAudioFormatException
- If the output audio format is not supported.
-
setEndTimeUs
void setEndTimeUs(long endTimeUs)
Deprecated.Sets the end time of the output audio.The mixer will not accept input nor produce output past this point.
- Parameters:
endTimeUs
- The end time in microseconds.- Throws:
IllegalArgumentException
- IfendTimeUs
is before the configured start time.
-
supportsSourceAudioFormat
boolean supportsSourceAudioFormat(AudioProcessor.AudioFormat sourceFormat)
Deprecated.Indicates whether the mixer supports mixing sources with the given audio format.
-
addSource
int addSource(AudioProcessor.AudioFormat sourceFormat, long startTimeUs) throws AudioProcessor.UnhandledAudioFormatException
Deprecated.Adds an audio source to mix starting at the given time.If the mixer has already output samples past the
startTimeUs
, audio from this source will be discarded up to the last output end timestamp.If the source start time is earlier than the configured mixer start time then audio from this source will be discarded up to the mixer start time.
All audio sources start with a volume of 1.0 on all channels.
- Parameters:
sourceFormat
- Audio format of source buffers.startTimeUs
- Source start time in microseconds.- Returns:
- Non-negative integer identifying the source (
sourceId
). - Throws:
AudioProcessor.UnhandledAudioFormatException
- If the source format is not supported.
-
setSourceVolume
void setSourceVolume(int sourceId, float volume)
Deprecated.Sets the volume applied to future samples queued from the given source.- Parameters:
sourceId
- Source identifier fromaddSource(com.google.android.exoplayer2.audio.AudioProcessor.AudioFormat, long)
.volume
- Non-negative scalar applied to all source channels.
-
removeSource
void removeSource(int sourceId)
Deprecated.Removes an audio source.No more audio can be queued from this source. All audio queued before removal will be output.
- Parameters:
sourceId
- Source identifier fromaddSource(com.google.android.exoplayer2.audio.AudioProcessor.AudioFormat, long)
.
-
queueInput
void queueInput(int sourceId, ByteBuffer sourceBuffer)
Deprecated.Queues audio data between the position and limit of thesourceBuffer
.After calling this method output may be available via
getOutput()
if all sources have queued data.- Parameters:
sourceId
- Source identifier fromaddSource(com.google.android.exoplayer2.audio.AudioProcessor.AudioFormat, long)
.sourceBuffer
- The source buffer to mix. It must be a direct byte buffer with native byte order. Its contents are treated as read-only. Its position will be advanced by the number of bytes consumed (which may be zero). The caller retains ownership of the provided buffer.
-
getOutput
ByteBuffer getOutput()
Deprecated.Returns a buffer containing output audio data between its position and limit.The buffer will be no larger than the configured buffer size and will include no more than the frames that have been queued from all sources, up to the end time. Silence will be generated for any periods with no sources.
The buffer will always be a direct byte buffer with native byte order. Calling this method invalidates any previously returned buffer. The buffer will be empty if no output is available.
- Returns:
- A buffer containing output data between its position and limit.
-
isEnded
boolean isEnded()
Deprecated.
-
reset
void reset()
Deprecated.Resets the mixer to its unconfigured state, releasing any resources.
-
-