docs/doc/reference/com/google/android/exoplayer2/audio/DefaultAudioSink.html
Package com.google.android.exoplayer2.audio
All Implemented Interfaces:AudioSink
[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public final classDefaultAudioSinkextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")implements[AudioSink](AudioSink.html "interface in com.google.android.exoplayer2.audio")
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.
Plays audio data. The implementation delegates to an AudioTrack and handles playback position smoothing, non-blocking writes and reconfiguration.
If tunneling mode is enabled, care must be taken that audio processors do not output buffers with a different duration than their input, and buffer processors must produce output corresponding to their last input immediately after that input is queued. This means that, for example, speed adjustment is not possible while using tunneling.
Nested Classes | Modifier and Type | Class | Description |
| --- | --- | --- |
| static interface | DefaultAudioSink.AudioProcessorChain |
Deprecated.
Use AudioProcessorChain.
|
| static interface | DefaultAudioSink.AudioTrackBufferSizeProvider |
Deprecated.
Provides the buffer size to use when creating an AudioTrack.
|
| static class | DefaultAudioSink.Builder |
Deprecated.
A builder to create DefaultAudioSink instances.
|
| static class | DefaultAudioSink.DefaultAudioProcessorChain |
Deprecated.
The default audio processor chain, which applies a (possibly empty) chain of user-defined audio processors followed by SilenceSkippingAudioProcessor and SonicAudioProcessor.
|
| static class | DefaultAudioSink.InvalidAudioTrackTimestampException |
Deprecated.
Thrown when the audio track has provided a spurious timestamp, if failOnSpuriousAudioTimestamp is set.
|
| static interface | DefaultAudioSink.OffloadMode |
Deprecated.
Audio offload mode configuration.
|
| static interface | DefaultAudioSink.OutputMode |
Deprecated.
Output mode of the audio sink. |
-
AudioSink.ConfigurationException, AudioSink.InitializationException, AudioSink.Listener, AudioSink.SinkFormatSupport, AudioSink.UnexpectedDiscontinuityException, AudioSink.WriteException
Fields | Modifier and Type | Field | Description |
| --- | --- | --- |
| static float | DEFAULT_PLAYBACK_SPEED |
Deprecated.
The default playback speed.
|
| static boolean | failOnSpuriousAudioTimestamp |
Deprecated.
Whether to throw an DefaultAudioSink.InvalidAudioTrackTimestampException when a spurious timestamp is reported from AudioTrack.getTimestamp(android.media.AudioTimestamp).
|
| static float | MAX_PITCH |
Deprecated.
The maximum allowed pitch factor.
|
| static float | MAX_PLAYBACK_SPEED |
Deprecated.
The maximum allowed playback speed.
|
| static float | MIN_PITCH |
Deprecated.
The minimum allowed pitch factor.
|
| static float | MIN_PLAYBACK_SPEED |
Deprecated.
The minimum allowed playback speed.
|
| static int | OFFLOAD_MODE_DISABLED |
Deprecated.
The audio sink will never play in offload mode.
|
| static int | OFFLOAD_MODE_ENABLED_GAPLESS_DISABLED |
Deprecated.
The audio sink will prefer offload playback, disabling gapless offload support.
|
| static int | OFFLOAD_MODE_ENABLED_GAPLESS_NOT_REQUIRED |
Deprecated.
The audio sink will prefer offload playback even if this might result in silence gaps between tracks.
|
| static int | OFFLOAD_MODE_ENABLED_GAPLESS_REQUIRED |
Deprecated.
The audio sink will prefer offload playback except if the track is gapless and the device does not advertise support for gapless playback in offload.
|
| static int | OUTPUT_MODE_OFFLOAD |
Deprecated.
The audio sink plays encoded audio in offload.
|
| static int | OUTPUT_MODE_PASSTHROUGH |
Deprecated.
The audio sink plays encoded audio in passthrough.
|
| static int | OUTPUT_MODE_PCM |
Deprecated.
The audio sink plays PCM audio. |
-
CURRENT_POSITION_NOT_SET, SINK_FORMAT_SUPPORTED_DIRECTLY, SINK_FORMAT_SUPPORTED_WITH_TRANSCODING, SINK_FORMAT_UNSUPPORTED
All Methods Instance Methods Concrete Methods Deprecated Methods | Modifier and Type | Method | Description |
| --- | --- | --- |
| void | configure(Format inputFormat, int specifiedBufferSize, int[] outputChannels) |
Deprecated.
Configures (or reconfigures) the sink.
|
| void | disableTunneling() |
Deprecated.
Disables tunneling.
|
| void | enableTunnelingV21() |
Deprecated.
Enables tunneling, if possible.
|
| void | experimentalFlushWithoutAudioTrackRelease() |
Deprecated.
Flushes the sink, after which it is ready to receive buffers from a new playback position.
|
| void | flush() |
Deprecated.
Flushes the sink, after which it is ready to receive buffers from a new playback position.
|
| AudioAttributes | getAudioAttributes() |
Deprecated.
Returns the audio attributes used for audio playback, or null if the sink does not use audio attributes.
|
| long | getCurrentPositionUs(boolean sourceEnded) |
Deprecated.
Returns the playback position in the stream starting at zero, in microseconds, or AudioSink.CURRENT_POSITION_NOT_SET if it is not yet available.
|
| @com.google.android.exoplayer2.audio.AudioSink.SinkFormatSupport int | getFormatSupport(Format format) |
Deprecated.
Returns the level of support that the sink provides for a given Format.
|
| PlaybackParameters | getPlaybackParameters() |
Deprecated.
Returns the active PlaybackParameters.
|
| boolean | getSkipSilenceEnabled() |
Deprecated.
Returns whether silences are skipped in the audio stream.
|
| boolean | handleBuffer(ByteBuffer buffer, long presentationTimeUs, int encodedAccessUnitCount) |
Deprecated.
Attempts to process data from a ByteBuffer, starting from its current position and ending at its limit (exclusive).
|
| void | handleDiscontinuity() |
Deprecated.
Signals to the sink that the next buffer may be discontinuous with the previous buffer.
|
| boolean | hasPendingData() |
Deprecated.
Returns whether the sink has data pending that has not been consumed yet.
|
| boolean | isEnded() |
Deprecated.
Returns whether AudioSink.playToEndOfStream() has been called and all buffers have been processed.
|
| void | onAudioCapabilitiesChanged(AudioCapabilities audioCapabilities) |
Deprecated.
|
| void | pause() |
Deprecated.
Pauses playback.
|
| void | play() |
Deprecated.
Starts or resumes consuming audio if initialized.
|
| void | playToEndOfStream() |
Deprecated.
Processes any remaining data.
|
| void | release() |
Deprecated.
Releases the audio sink.
|
| void | reset() |
Deprecated.
Resets the sink, releasing any resources that it currently holds.
|
| void | setAudioAttributes(AudioAttributes audioAttributes) |
Deprecated.
Sets attributes for audio playback.
|
| void | setAudioSessionId(int audioSessionId) |
Deprecated.
Sets the audio session id.
|
| void | setAuxEffectInfo(AuxEffectInfo auxEffectInfo) |
Deprecated.
Sets the auxiliary effect.
|
| void | setListener(AudioSink.Listener listener) |
Deprecated.
Sets the listener for sink events, which should be the audio renderer.
|
| void | setPlaybackParameters(PlaybackParameters playbackParameters) |
Deprecated.
Attempts to set the playback parameters.
|
| void | setPlayerId(PlayerId playerId) |
Deprecated.
Sets the PlayerId of the player using this audio sink.
|
| void | setPreferredDevice(AudioDeviceInfo audioDeviceInfo) |
Deprecated.
Sets the preferred audio device.
|
| void | setSkipSilenceEnabled(boolean skipSilenceEnabled) |
Deprecated.
Sets whether silences should be skipped in the audio stream.
|
| void | setVolume(float volume) |
Deprecated.
Sets the playback volume.
|
| boolean | supportsFormat(Format format) |
Deprecated.
Returns whether the sink supports a given Format.
|
-
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
setOutputStreamOffsetUs
-
public static final float DEFAULT_PLAYBACK_SPEED
Deprecated.
The default playback speed. See Also:Constant Field Values
-
public static final float MIN_PLAYBACK_SPEED
Deprecated.
The minimum allowed playback speed. Lower values will be constrained to fall in range. See Also:Constant Field Values
-
public static final float MAX_PLAYBACK_SPEED
Deprecated.
The maximum allowed playback speed. Higher values will be constrained to fall in range. See Also:Constant Field Values
-
public static final float MIN_PITCH
Deprecated.
The minimum allowed pitch factor. Lower values will be constrained to fall in range. See Also:Constant Field Values
-
public static final float MAX_PITCH
Deprecated.
The maximum allowed pitch factor. Higher values will be constrained to fall in range. See Also:Constant Field Values
-
public static final int OFFLOAD_MODE_DISABLED
Deprecated.
The audio sink will never play in offload mode. See Also:Constant Field Values
-
public static final int OFFLOAD_MODE_ENABLED_GAPLESS_REQUIRED
Deprecated.
The audio sink will prefer offload playback except if the track is gapless and the device does not advertise support for gapless playback in offload.
Use this option to prioritize seamless transitions between tracks of the same album to power savings.
See Also:Constant Field Values
-
public static final int OFFLOAD_MODE_ENABLED_GAPLESS_NOT_REQUIRED
Deprecated.
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.
See Also:Constant Field Values
-
public static final int OFFLOAD_MODE_ENABLED_GAPLESS_DISABLED
Deprecated.
The audio sink will prefer offload playback, disabling gapless offload support.
Use this option if gapless has undesirable side effects. For example if it introduces hardware issues.
See Also:Constant Field Values
-
public static final int OUTPUT_MODE_PCM
Deprecated.
The audio sink plays PCM audio. See Also:Constant Field Values
-
public static final int OUTPUT_MODE_OFFLOAD
Deprecated.
The audio sink plays encoded audio in offload. See Also:Constant Field Values
-
public static final int OUTPUT_MODE_PASSTHROUGH
Deprecated.
The audio sink plays encoded audio in passthrough. See Also:Constant Field Values
-
public static boolean failOnSpuriousAudioTimestamp
Deprecated.
Whether to throw an DefaultAudioSink.InvalidAudioTrackTimestampException when a spurious timestamp is reported from AudioTrack.getTimestamp(android.media.AudioTimestamp).
The flag must be set before creating a player. Should be set to true for testing and debugging purposes only.
-
public void setListener([AudioSink.Listener](AudioSink.Listener.html "interface in com.google.android.exoplayer2.audio")listener)
Deprecated.
Description copied from interface: AudioSink
Sets the listener for sink events, which should be the audio renderer.
Specified by:setListener in interface AudioSinkParameters:listener - The listener for sink events, which should be the audio renderer.
-
public void setPlayerId(@Nullable[PlayerId](../analytics/PlayerId.html "class in com.google.android.exoplayer2.analytics")playerId)
Deprecated.
Description copied from interface: AudioSink
Sets the PlayerId of the player using this audio sink.
Specified by:setPlayerId in interface AudioSinkParameters:playerId - The PlayerId, or null to clear a previously set id.
-
public boolean supportsFormat([Format](../Format.html "class in com.google.android.exoplayer2")format)
Deprecated.
Description copied from interface: AudioSink
Returns whether the sink supports a given Format.
Specified by:supportsFormat in interface AudioSinkParameters:format - The format.Returns:Whether the sink supports the format.
-
public @com.google.android.exoplayer2.audio.AudioSink.SinkFormatSupport int getFormatSupport([Format](../Format.html "class in com.google.android.exoplayer2")format)
Deprecated.
Description copied from interface: AudioSink
Returns the level of support that the sink provides for a given Format.
Specified by:getFormatSupport in interface AudioSinkParameters:format - The format.Returns:The level of support provided.
-
public long getCurrentPositionUs(boolean sourceEnded)
Deprecated.
Description copied from interface: AudioSink
Returns the playback position in the stream starting at zero, in microseconds, or AudioSink.CURRENT_POSITION_NOT_SET if it is not yet available.
Specified by:getCurrentPositionUs in interface AudioSinkParameters:sourceEnded - Specify true if no more input buffers will be provided.Returns:The playback position relative to the start of playback, in microseconds.
-
public void configure([Format](../Format.html "class in com.google.android.exoplayer2")inputFormat,
int specifiedBufferSize,
@Nullable
int[] outputChannels)
throws[AudioSink.ConfigurationException](AudioSink.ConfigurationException.html "class in com.google.android.exoplayer2.audio")
Deprecated.
Description copied from interface: AudioSink
Configures (or reconfigures) the sink.
Specified by:configure in interface AudioSinkParameters:inputFormat - The format of audio data provided in the input buffers.specifiedBufferSize - A specific size for the playback buffer in bytes, or 0 to infer a suitable buffer size.outputChannels - A mapping from input to output channels that is applied to this sink's input as a preprocessing step, if handling PCM input. Specify null to leave the input unchanged. Otherwise, the element at index i specifies index of the input channel to map to output channel i when preprocessing input buffers. After the map is applied the audio data will have outputChannels.length channels.Throws:AudioSink.ConfigurationException - If an error occurs configuring the sink.
-
public void play()
Deprecated.
Description copied from interface: AudioSink
Starts or resumes consuming audio if initialized.
Specified by:play in interface AudioSink
-
public void handleDiscontinuity()
Deprecated.
Description copied from interface: AudioSink
Signals to the sink that the next buffer may be discontinuous with the previous buffer.
Specified by:handleDiscontinuity in interface AudioSink
-
public boolean handleBuffer([ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html "class or interface in java.nio")buffer,
long presentationTimeUs,
int encodedAccessUnitCount)
throws[AudioSink.InitializationException](AudioSink.InitializationException.html "class in com.google.android.exoplayer2.audio"),[AudioSink.WriteException](AudioSink.WriteException.html "class in com.google.android.exoplayer2.audio")
Deprecated.
Description copied from interface: AudioSink
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. 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 ByteBuffer must be provided to subsequent calls until it has been fully consumed, except in the case of an intervening call to AudioSink.flush() (or to AudioSink.configure(Format, int, int[]) that causes the sink to be flushed).
Specified by:handleBuffer in interface AudioSinkParameters:buffer - The buffer containing audio data.presentationTimeUs - The presentation timestamp of the buffer in microseconds.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:Whether the buffer was handled fully.Throws:AudioSink.InitializationException - If an error occurs initializing the sink.AudioSink.WriteException - If an error occurs writing the audio data.
-
public void playToEndOfStream()
throws[AudioSink.WriteException](AudioSink.WriteException.html "class in com.google.android.exoplayer2.audio")
Deprecated.
Description copied from interface: AudioSink
Processes any remaining data. AudioSink.isEnded() will return true when no data remains.
Specified by:playToEndOfStream in interface AudioSinkThrows:AudioSink.WriteException - If an error occurs draining data to the sink.
-
public boolean isEnded()
Deprecated.
Description copied from interface: AudioSink
Returns whether AudioSink.playToEndOfStream() has been called and all buffers have been processed.
Specified by:isEnded in interface AudioSink
-
public boolean hasPendingData()
Deprecated.
Description copied from interface: AudioSink
Returns whether the sink has data pending that has not been consumed yet.
Specified by:hasPendingData in interface AudioSink
-
public void setPlaybackParameters([PlaybackParameters](../PlaybackParameters.html "class in com.google.android.exoplayer2")playbackParameters)
Deprecated.
Description copied from interface: AudioSink
Attempts to set the playback parameters. The audio sink may override these parameters if they are not supported.
Specified by:setPlaybackParameters in interface AudioSinkParameters:playbackParameters - The new playback parameters to attempt to set.
-
public[PlaybackParameters](../PlaybackParameters.html "class in com.google.android.exoplayer2")getPlaybackParameters()
Deprecated.
Description copied from interface: AudioSink
Returns the active PlaybackParameters.
Specified by:getPlaybackParameters in interface AudioSink
-
public void setSkipSilenceEnabled(boolean skipSilenceEnabled)
Deprecated.
Description copied from interface: AudioSink
Sets whether silences should be skipped in the audio stream.
Specified by:setSkipSilenceEnabled in interface AudioSink
-
public boolean getSkipSilenceEnabled()
Deprecated.
Description copied from interface: AudioSink
Returns whether silences are skipped in the audio stream.
Specified by:getSkipSilenceEnabled in interface AudioSink
-
public void setAudioAttributes([AudioAttributes](AudioAttributes.html "class in com.google.android.exoplayer2.audio")audioAttributes)
Deprecated.
Description copied from interface: AudioSink
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.
Specified by:setAudioAttributes in interface AudioSinkParameters:audioAttributes - The attributes for audio playback.
-
public[AudioAttributes](AudioAttributes.html "class in com.google.android.exoplayer2.audio")getAudioAttributes()
Deprecated.
Description copied from interface: AudioSink
Returns the audio attributes used for audio playback, or null if the sink does not use audio attributes.
Specified by:getAudioAttributes in interface AudioSink
-
public void setAudioSessionId(int audioSessionId)
Deprecated.
Description copied from interface: AudioSink
Sets the audio session id.
Specified by:setAudioSessionId in interface AudioSink
-
public void setAuxEffectInfo([AuxEffectInfo](AuxEffectInfo.html "class in com.google.android.exoplayer2.audio")auxEffectInfo)
Deprecated.
Description copied from interface: AudioSink
Sets the auxiliary effect.
Specified by:setAuxEffectInfo in interface AudioSink
-
@RequiresApi(23)
public void setPreferredDevice(@Nullable[AudioDeviceInfo](https://developer.android.com/reference/android/media/AudioDeviceInfo.html "class or interface in android.media")audioDeviceInfo)
Deprecated.
Description copied from interface: AudioSink
Sets the preferred audio device.
Specified by:setPreferredDevice in interface AudioSinkParameters:audioDeviceInfo - The preferred audio device, or null to restore the default.
-
public void enableTunnelingV21()
Deprecated.
Description copied from interface: AudioSink
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 AudioTrack, and requires platform API version 21 onwards.
Specified by:enableTunnelingV21 in interface AudioSink
-
public void disableTunneling()
Deprecated.
Description copied from interface: AudioSink
Disables tunneling. If tunneling was previously enabled then the sink is reset and any audio session id is cleared.
Specified by:disableTunneling in interface AudioSink
-
public void setVolume(float volume)
Deprecated.
Description copied from interface: AudioSink
Sets the playback volume.
Specified by:setVolume in interface AudioSinkParameters:volume - Linear output gain to apply to all channels. Should be in the range [0.0, 1.0].
-
public void pause()
Deprecated.
Description copied from interface: AudioSink
Pauses playback.
Specified by:pause in interface AudioSink
-
public void flush()
Deprecated.
Description copied from interface: AudioSink
Flushes the sink, after which it is ready to receive buffers from a new playback position.
The audio session may remain active until AudioSink.reset() is called.
Specified by:flush in interface AudioSink
-
public void experimentalFlushWithoutAudioTrackRelease()
Deprecated.
Description copied from interface: AudioSink
Flushes the sink, after which it is ready to receive buffers from a new playback position.
Does not release the AudioTrack held by the sink.
This method is experimental, and will be renamed or removed in a future release.
Only for experimental use as part of MediaCodecAudioRenderer.experimentalSetEnableKeepAudioTrackOnSeek(boolean).
Specified by:experimentalFlushWithoutAudioTrackRelease in interface AudioSink
-
public void reset()
Deprecated.
Description copied from interface: AudioSink
Resets the sink, releasing any resources that it currently holds.
Specified by:reset in interface AudioSink
-
public void release()
Deprecated.
Description copied from interface: AudioSink
Releases the audio sink.
Specified by:release in interface AudioSink
-
public void onAudioCapabilitiesChanged([AudioCapabilities](AudioCapabilities.html "class in com.google.android.exoplayer2.audio")audioCapabilities)
Deprecated.