public class AudioTrack extends PlayerBase implements AudioRouting
write(byte[], int, int)
, write(short[], int, int)
,
and write(float[], int, int, int)
methods.
An AudioTrack instance can operate under two modes: static or streaming.
In Streaming mode, the application writes a continuous stream of data to the AudioTrack, using
one of the write()
methods. These are blocking and return when the data has been
transferred from the Java layer to the native layer and queued for playback. The streaming
mode is most useful when playing blocks of audio data that for instance are:
Upon creation, an AudioTrack object initializes its associated audio buffer.
The size of this buffer, specified during the construction, determines how long an AudioTrack
can play before running out of data.
For an AudioTrack using the static mode, this size is the maximum size of the sound that can
be played from it.
For the streaming mode, data will be written to the audio sink in chunks of
sizes less than or equal to the total buffer size.
AudioTrack is not final and thus permits subclasses, but such use is not recommended.
Modifier and Type | Class and Description |
---|---|
static class |
AudioTrack.Builder
Builder class for
AudioTrack objects. |
static interface |
AudioTrack.OnPlaybackPositionUpdateListener
Interface definition for a callback to be invoked when the playback head position of
an AudioTrack has reached a notification marker or has increased by a certain period.
|
static interface |
AudioTrack.OnRoutingChangedListener
Deprecated.
users should switch to the general purpose
AudioRouting.OnRoutingChangedListener class instead. |
static interface |
AudioTrack.TransferMode |
static interface |
AudioTrack.WriteMode |
Modifier and Type | Field and Description |
---|---|
static int |
CHANNEL_COUNT_MAX
Maximum value for AudioTrack channel count
|
static int |
ERROR
Denotes a generic operation failure.
|
static int |
ERROR_BAD_VALUE
Denotes a failure due to the use of an invalid value.
|
static int |
ERROR_DEAD_OBJECT
An error code indicating that the object reporting it is no longer valid and needs to
be recreated.
|
static int |
ERROR_INVALID_OPERATION
Denotes a failure due to the improper use of a method.
|
static int |
ERROR_WOULD_BLOCK
getTimestampWithStatus(AudioTimestamp) is called in STOPPED or FLUSHED state,
or immediately after start/ACTIVE. |
protected long |
mNativeTrackInJavaObj |
static int |
MODE_STATIC
Creation mode where audio data is transferred from Java to the native layer
only once before the audio starts playing.
|
static int |
MODE_STREAM
Creation mode where audio data is streamed from Java to the native layer
as the audio is playing.
|
static int |
PLAYSTATE_PAUSED
indicates AudioTrack state is paused
|
static int |
PLAYSTATE_PLAYING
indicates AudioTrack state is playing
|
static int |
PLAYSTATE_STOPPED
indicates AudioTrack state is stopped
|
static int |
STATE_INITIALIZED
State of an AudioTrack that is ready to be used.
|
static int |
STATE_NO_STATIC_DATA
State of a successfully initialized AudioTrack that uses static data,
but that hasn't received that data yet.
|
static int |
STATE_UNINITIALIZED
State of an AudioTrack that was not successfully initialized upon creation.
|
static int |
SUCCESS
Denotes a successful operation.
|
static int |
WRITE_BLOCKING
The write mode indicating the write operation will block until all data has been written,
to be used as the actual value of the writeMode parameter in
write(byte[], int, int, int) , write(short[], int, int, int) ,
write(float[], int, int, int) , write(ByteBuffer, int, int) , and
write(ByteBuffer, int, int, long) . |
static int |
WRITE_NON_BLOCKING
The write mode indicating the write operation will return immediately after
queuing as much audio data for playback as possible without blocking,
to be used as the actual value of the writeMode parameter in
write(ByteBuffer, int, int) , write(short[], int, int, int) ,
write(float[], int, int, int) , write(ByteBuffer, int, int) , and
write(ByteBuffer, int, int, long) . |
mAttributes, mAuxEffectSendLevel, mLeftVolume, mRightVolume
Constructor and Description |
---|
AudioTrack(AudioAttributes attributes,
AudioFormat format,
int bufferSizeInBytes,
int mode,
int sessionId)
Class constructor with
AudioAttributes and AudioFormat . |
AudioTrack(int streamType,
int sampleRateInHz,
int channelConfig,
int audioFormat,
int bufferSizeInBytes,
int mode)
Class constructor.
|
AudioTrack(int streamType,
int sampleRateInHz,
int channelConfig,
int audioFormat,
int bufferSizeInBytes,
int mode,
int sessionId)
Class constructor with audio session.
|
Modifier and Type | Method and Description |
---|---|
void |
addOnRoutingChangedListener(AudioRouting.OnRoutingChangedListener listener,
Handler handler)
Adds an
AudioRouting.OnRoutingChangedListener to receive notifications of routing
changes on this AudioTrack. |
void |
addOnRoutingChangedListener(AudioTrack.OnRoutingChangedListener listener,
Handler handler)
Deprecated.
users should switch to the general purpose
AudioRouting.OnRoutingChangedListener class instead. |
int |
attachAuxEffect(int effectId)
Attaches an auxiliary effect to the audio track.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
void |
flush()
Flushes the audio data currently queued for playback.
|
int |
getAudioFormat()
Returns the configured audio data encoding.
|
int |
getAudioSessionId()
Returns the audio session ID.
|
int |
getBufferCapacityInFrames()
Returns the maximum size of the
AudioTrack buffer in frames. |
int |
getBufferSizeInFrames()
Returns the effective size of the
AudioTrack buffer
that the application writes to. |
int |
getChannelConfiguration()
Returns the configured channel position mask.
|
int |
getChannelCount()
Returns the configured number of channels.
|
AudioFormat |
getFormat()
Returns the configured
AudioTrack format. |
int |
getLatency()
Returns this track's estimated latency in milliseconds.
|
static float |
getMaxVolume()
Returns the maximum gain value, which is greater than or equal to 1.0.
|
static int |
getMinBufferSize(int sampleRateInHz,
int channelConfig,
int audioFormat)
Returns the estimated minimum buffer size required for an AudioTrack
object to be created in the
MODE_STREAM mode. |
static float |
getMinVolume()
Returns the minimum gain value, which is the constant 0.0.
|
protected int |
getNativeFrameCount()
Deprecated.
Use the identical public method
getBufferSizeInFrames() instead. |
static int |
getNativeOutputSampleRate(int streamType)
Returns the output sample rate in Hz for the specified stream type.
|
int |
getNotificationMarkerPosition()
Returns marker position expressed in frames.
|
int |
getPlaybackHeadPosition()
Returns the playback head position expressed in frames.
|
PlaybackParams |
getPlaybackParams()
Returns the current playback parameters.
|
int |
getPlaybackRate()
Returns the current playback sample rate rate in Hz.
|
int |
getPlayState()
Returns the playback state of the AudioTrack instance.
|
int |
getPositionNotificationPeriod()
Returns the notification update period expressed in frames.
|
AudioDeviceInfo |
getPreferredDevice()
Returns the selected output specified by
setPreferredDevice(android.media.AudioDeviceInfo) . |
AudioDeviceInfo |
getRoutedDevice()
Returns an
AudioDeviceInfo identifying the current routing of this AudioTrack. |
int |
getSampleRate()
Returns the configured audio source sample rate in Hz.
|
int |
getState()
Returns the state of the AudioTrack instance.
|
int |
getStreamType()
Returns the type of audio stream this AudioTrack is configured for.
|
boolean |
getTimestamp(AudioTimestamp timestamp)
Poll for a timestamp on demand.
|
int |
getTimestampWithStatus(AudioTimestamp timestamp)
Poll for a timestamp on demand.
|
int |
getUnderrunCount()
Returns the number of underrun occurrences in the application-level write buffer
since the AudioTrack was created.
|
void |
native_release() |
void |
pause()
Pauses the playback of the audio data.
|
void |
play()
Starts playing an AudioTrack.
|
void |
release()
Releases the native AudioTrack resources.
|
int |
reloadStaticData()
Sets the playback head position within the static buffer to zero,
that is it rewinds to start of static buffer.
|
void |
removeOnRoutingChangedListener(AudioRouting.OnRoutingChangedListener listener)
Removes an
AudioRouting.OnRoutingChangedListener which has been previously added
to receive rerouting notifications. |
void |
removeOnRoutingChangedListener(AudioTrack.OnRoutingChangedListener listener)
Deprecated.
users should switch to the general purpose
AudioRouting.OnRoutingChangedListener class instead. |
int |
setAuxEffectSendLevel(float level)
Sets the send level of the audio track to the attached auxiliary effect
attachAuxEffect(int) . |
int |
setBufferSizeInFrames(int bufferSizeInFrames)
Limits the effective size of the
AudioTrack buffer
that the application writes to. |
int |
setLoopPoints(int startInFrames,
int endInFrames,
int loopCount)
Sets the loop points and the loop count.
|
int |
setNotificationMarkerPosition(int markerInFrames)
Sets the position of the notification marker.
|
int |
setPlaybackHeadPosition(int positionInFrames)
Sets the playback head position within the static buffer.
|
void |
setPlaybackParams(PlaybackParams params)
Sets the playback parameters.
|
void |
setPlaybackPositionUpdateListener(AudioTrack.OnPlaybackPositionUpdateListener listener)
Sets the listener the AudioTrack notifies when a previously set marker is reached or
for each periodic playback head position update.
|
void |
setPlaybackPositionUpdateListener(AudioTrack.OnPlaybackPositionUpdateListener listener,
Handler handler)
Sets the listener the AudioTrack notifies when a previously set marker is reached or
for each periodic playback head position update.
|
int |
setPlaybackRate(int sampleRateInHz)
Sets the playback sample rate for this track.
|
int |
setPositionNotificationPeriod(int periodInFrames)
Sets the period for the periodic notification event.
|
boolean |
setPreferredDevice(AudioDeviceInfo deviceInfo)
Specifies an audio device (via an
AudioDeviceInfo object) to route
the output from this AudioTrack. |
protected void |
setState(int state)
Deprecated.
Only accessible by subclasses, which are not recommended for AudioTrack.
|
int |
setStereoVolume(float leftGain,
float rightGain)
Deprecated.
Applications should use
setVolume(float) instead, as it
more gracefully scales down to mono, and up to multi-channel content beyond stereo. |
int |
setVolume(float gain)
Sets the specified output gain value on all channels of this track.
|
void |
stop()
Stops playing the audio data.
|
int |
write(byte[] audioData,
int offsetInBytes,
int sizeInBytes)
Writes the audio data to the audio sink for playback (streaming mode),
or copies audio data for later playback (static buffer mode).
|
int |
write(byte[] audioData,
int offsetInBytes,
int sizeInBytes,
int writeMode)
Writes the audio data to the audio sink for playback (streaming mode),
or copies audio data for later playback (static buffer mode).
|
int |
write(ByteBuffer audioData,
int sizeInBytes,
int writeMode)
Writes the audio data to the audio sink for playback (streaming mode),
or copies audio data for later playback (static buffer mode).
|
int |
write(ByteBuffer audioData,
int sizeInBytes,
int writeMode,
long timestamp)
Writes the audio data to the audio sink for playback in streaming mode on a HW_AV_SYNC track.
|
int |
write(float[] audioData,
int offsetInFloats,
int sizeInFloats,
int writeMode)
Writes the audio data to the audio sink for playback (streaming mode),
or copies audio data for later playback (static buffer mode).
|
int |
write(short[] audioData,
int offsetInShorts,
int sizeInShorts)
Writes the audio data to the audio sink for playback (streaming mode),
or copies audio data for later playback (static buffer mode).
|
int |
write(short[] audioData,
int offsetInShorts,
int sizeInShorts,
int writeMode)
Writes the audio data to the audio sink for playback (streaming mode),
or copies audio data for later playback (static buffer mode).
|
public static final int CHANNEL_COUNT_MAX
public static final int PLAYSTATE_STOPPED
public static final int PLAYSTATE_PAUSED
public static final int PLAYSTATE_PLAYING
public static final int MODE_STATIC
public static final int MODE_STREAM
public static final int STATE_UNINITIALIZED
public static final int STATE_INITIALIZED
public static final int STATE_NO_STATIC_DATA
public static final int SUCCESS
public static final int ERROR
public static final int ERROR_BAD_VALUE
public static final int ERROR_INVALID_OPERATION
public static final int ERROR_DEAD_OBJECT
public static final int ERROR_WOULD_BLOCK
getTimestampWithStatus(AudioTimestamp)
is called in STOPPED or FLUSHED state,
or immediately after start/ACTIVE.public static final int WRITE_BLOCKING
write(byte[], int, int, int)
, write(short[], int, int, int)
,
write(float[], int, int, int)
, write(ByteBuffer, int, int)
, and
write(ByteBuffer, int, int, long)
.public static final int WRITE_NON_BLOCKING
write(ByteBuffer, int, int)
, write(short[], int, int, int)
,
write(float[], int, int, int)
, write(ByteBuffer, int, int)
, and
write(ByteBuffer, int, int, long)
.protected long mNativeTrackInJavaObj
public AudioTrack(int streamType, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes, int mode) throws IllegalArgumentException
streamType
- the type of the audio stream. See
AudioManager.STREAM_VOICE_CALL
, AudioManager.STREAM_SYSTEM
,
AudioManager.STREAM_RING
, AudioManager.STREAM_MUSIC
,
AudioManager.STREAM_ALARM
, and AudioManager.STREAM_NOTIFICATION
.sampleRateInHz
- the initial source sample rate expressed in Hz.
AudioFormat.SAMPLE_RATE_UNSPECIFIED
means to use a route-dependent value
which is usually the sample rate of the sink.
getSampleRate()
can be used to retrieve the actual sample rate chosen.channelConfig
- describes the configuration of the audio channels.
See AudioFormat.CHANNEL_OUT_MONO
and
AudioFormat.CHANNEL_OUT_STEREO
audioFormat
- the format in which the audio data is represented.
See AudioFormat.ENCODING_PCM_16BIT
,
AudioFormat.ENCODING_PCM_8BIT
,
and AudioFormat.ENCODING_PCM_FLOAT
.bufferSizeInBytes
- the total size (in bytes) of the internal buffer where audio data is
read from for playback. This should be a nonzero multiple of the frame size in bytes.
If the track's creation mode is MODE_STATIC
,
this is the maximum length sample, or audio clip, that can be played by this instance.
If the track's creation mode is MODE_STREAM
,
this should be the desired buffer size
for the AudioTrack
to satisfy the application's
latency requirements.
If bufferSizeInBytes
is less than the
minimum buffer size for the output sink, it is increased to the minimum
buffer size.
The method getBufferSizeInFrames()
returns the
actual size in frames of the buffer created, which
determines the minimum frequency to write
to the streaming AudioTrack
to avoid underrun.
See getMinBufferSize(int, int, int)
to determine the estimated minimum buffer size
for an AudioTrack instance in streaming mode.
mode
- streaming or static buffer. See MODE_STATIC
and MODE_STREAM
IllegalArgumentException
public AudioTrack(int streamType, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes, int mode, int sessionId) throws IllegalArgumentException
getAudioSessionId()
method.
If a non-zero session ID is provided, this AudioTrack will share effects attached to this
session
with all other media players or audio tracks in the same session, otherwise a new session
will be created for this track if none is supplied.streamType
- the type of the audio stream. See
AudioManager.STREAM_VOICE_CALL
, AudioManager.STREAM_SYSTEM
,
AudioManager.STREAM_RING
, AudioManager.STREAM_MUSIC
,
AudioManager.STREAM_ALARM
, and AudioManager.STREAM_NOTIFICATION
.sampleRateInHz
- the initial source sample rate expressed in Hz.
AudioFormat.SAMPLE_RATE_UNSPECIFIED
means to use a route-dependent value
which is usually the sample rate of the sink.channelConfig
- describes the configuration of the audio channels.
See AudioFormat.CHANNEL_OUT_MONO
and
AudioFormat.CHANNEL_OUT_STEREO
audioFormat
- the format in which the audio data is represented.
See AudioFormat.ENCODING_PCM_16BIT
and
AudioFormat.ENCODING_PCM_8BIT
,
and AudioFormat.ENCODING_PCM_FLOAT
.bufferSizeInBytes
- the total size (in bytes) of the internal buffer where audio data is
read from for playback. This should be a nonzero multiple of the frame size in bytes.
If the track's creation mode is MODE_STATIC
,
this is the maximum length sample, or audio clip, that can be played by this instance.
If the track's creation mode is MODE_STREAM
,
this should be the desired buffer size
for the AudioTrack
to satisfy the application's
latency requirements.
If bufferSizeInBytes
is less than the
minimum buffer size for the output sink, it is increased to the minimum
buffer size.
The method getBufferSizeInFrames()
returns the
actual size in frames of the buffer created, which
determines the minimum frequency to write
to the streaming AudioTrack
to avoid underrun.
You can write data into this buffer in smaller chunks than this size.
See getMinBufferSize(int, int, int)
to determine the estimated minimum buffer size
for an AudioTrack instance in streaming mode.
mode
- streaming or static buffer. See MODE_STATIC
and MODE_STREAM
sessionId
- Id of audio session the AudioTrack must be attached toIllegalArgumentException
public AudioTrack(AudioAttributes attributes, AudioFormat format, int bufferSizeInBytes, int mode, int sessionId) throws IllegalArgumentException
AudioAttributes
and AudioFormat
.attributes
- a non-null AudioAttributes
instance.format
- a non-null AudioFormat
instance describing the format of the data
that will be played through this AudioTrack. See AudioFormat.Builder
for
configuring the audio format parameters such as encoding, channel mask and sample rate.bufferSizeInBytes
- the total size (in bytes) of the internal buffer where audio data is
read from for playback. This should be a nonzero multiple of the frame size in bytes.
If the track's creation mode is MODE_STATIC
,
this is the maximum length sample, or audio clip, that can be played by this instance.
If the track's creation mode is MODE_STREAM
,
this should be the desired buffer size
for the AudioTrack
to satisfy the application's
latency requirements.
If bufferSizeInBytes
is less than the
minimum buffer size for the output sink, it is increased to the minimum
buffer size.
The method getBufferSizeInFrames()
returns the
actual size in frames of the buffer created, which
determines the minimum frequency to write
to the streaming AudioTrack
to avoid underrun.
See getMinBufferSize(int, int, int)
to determine the estimated minimum buffer size
for an AudioTrack instance in streaming mode.
mode
- streaming or static buffer. See MODE_STATIC
and MODE_STREAM
.sessionId
- ID of audio session the AudioTrack must be attached to, or
AudioManager.AUDIO_SESSION_ID_GENERATE
if the session isn't known at construction
time. See also AudioManager.generateAudioSessionId()
to obtain a session ID before
construction.IllegalArgumentException
public void release()
protected void finalize()
Object
finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked
if and when the JavaTM virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize
method may take any action, including
making this object available again to other threads; the usual purpose
of finalize
, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize
method of class Object
performs no
special action; it simply returns normally. Subclasses of
Object
may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize
method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.
public static float getMinVolume()
The word "volume" in the API name is historical; this is actually a linear gain.
public static float getMaxVolume()
The word "volume" in the API name is historical; this is actually a gain. expressed as a linear multiplier on sample values, where a maximum value of 1.0 corresponds to a gain of 0 dB (sample values left unmodified).
public int getSampleRate()
setPlaybackRate(int)
is called.
If the constructor had a specific sample rate, then the initial sink sample rate is that
value.
If the constructor had AudioFormat.SAMPLE_RATE_UNSPECIFIED
,
then the initial sink sample rate is a route-dependent default value based on the source [sic].public int getPlaybackRate()
public PlaybackParams getPlaybackParams()
setPlaybackParams(PlaybackParams)
to set playback parametersPlaybackParams
.IllegalStateException
- if track is not initialized.public int getAudioFormat()
AudioFormat.ENCODING_PCM_8BIT
,
AudioFormat.ENCODING_PCM_16BIT
, and AudioFormat.ENCODING_PCM_FLOAT
.public int getStreamType()
AudioManager.STREAM_VOICE_CALL
,
AudioManager.STREAM_SYSTEM
, AudioManager.STREAM_RING
,
AudioManager.STREAM_MUSIC
, AudioManager.STREAM_ALARM
,
AudioManager.STREAM_NOTIFICATION
, or AudioManager.STREAM_DTMF
.public int getChannelConfiguration()
For example, refer to AudioFormat.CHANNEL_OUT_MONO
,
AudioFormat.CHANNEL_OUT_STEREO
, AudioFormat.CHANNEL_OUT_5POINT1
.
This method may return AudioFormat.CHANNEL_INVALID
if
a channel index mask was used. Consider
getFormat()
instead, to obtain an AudioFormat
,
which contains both the channel position mask and the channel index mask.
public AudioFormat getFormat()
AudioTrack
format.AudioFormat
containing the
AudioTrack
parameters at the time of configuration.public int getChannelCount()
public int getState()
STATE_UNINITIALIZED
,
STATE_INITIALIZED
,
STATE_NO_STATIC_DATA
public int getPlayState()
PLAYSTATE_STOPPED
,
PLAYSTATE_PAUSED
,
PLAYSTATE_PLAYING
public int getBufferSizeInFrames()
AudioTrack
buffer
that the application writes to.
This will be less than or equal to the result of
getBufferCapacityInFrames()
.
It will be equal if setBufferSizeInFrames(int)
has never been called.
If the track is subsequently routed to a different output sink, the buffer size and capacity may enlarge to accommodate.
If the AudioTrack
encoding indicates compressed data,
e.g. AudioFormat.ENCODING_AC3
, then the frame count returned is
the size of the AudioTrack
buffer in bytes.
See also AudioManager.getProperty(String)
for key
AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER
.
AudioTrack
buffer.IllegalStateException
- if track is not initialized.public int setBufferSizeInFrames(int bufferSizeInFrames)
AudioTrack
buffer
that the application writes to.
A write to this AudioTrack will not fill the buffer beyond this limit. If a blocking write is used then the write will block until the data can fit within this limit.
Changing this limit modifies the latency associated with the buffer for this track. A smaller size will give lower latency but there may be more glitches due to buffer underruns.
The actual size used may not be equal to this requested size.
It will be limited to a valid range with a maximum of
getBufferCapacityInFrames()
.
It may also be adjusted slightly for internal reasons.
If bufferSizeInFrames is less than zero then ERROR_BAD_VALUE
will be returned.
This method is only supported for PCM audio. It is not supported for compressed audio tracks.
bufferSizeInFrames
- requested buffer size in framesERROR_BAD_VALUE
, ERROR_INVALID_OPERATION
IllegalStateException
- if track is not initialized.public int getBufferCapacityInFrames()
AudioTrack
buffer in frames.
If the track's creation mode is MODE_STATIC
,
it is equal to the specified bufferSizeInBytes on construction, converted to frame units.
A static track's frame count will not change.
If the track's creation mode is MODE_STREAM
,
it is greater than or equal to the specified bufferSizeInBytes converted to frame units.
For streaming tracks, this value may be rounded up to a larger value if needed by
the target output sink, and
if the track is subsequently routed to a different output sink, the
frame count may enlarge to accommodate.
If the AudioTrack
encoding indicates compressed data,
e.g. AudioFormat.ENCODING_AC3
, then the frame count returned is
the size of the AudioTrack
buffer in bytes.
See also AudioManager.getProperty(String)
for key
AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER
.
AudioTrack
buffer.IllegalStateException
- if track is not initialized.@Deprecated protected int getNativeFrameCount()
getBufferSizeInFrames()
instead.AudioTrack
buffer.AudioTrack
buffer.IllegalStateException
public int getNotificationMarkerPosition()
getPlaybackHeadPosition()
,
or zero if marker is disabled.public int getPositionNotificationPeriod()
public int getPlaybackHeadPosition()
flush()
, reloadStaticData()
, and stop()
.
If the track's creation mode is MODE_STATIC
, the return value indicates
the total number of frames played since reset,
not the current offset within the buffer.public int getLatency()
public int getUnderrunCount()
Underruns are less likely when buffer sizes are large.
It may be possible to eliminate underruns by recreating the AudioTrack with
a larger buffer.
Or by using setBufferSizeInFrames(int)
to dynamically increase the
effective size of the buffer.
public static int getNativeOutputSampleRate(int streamType)
public static int getMinBufferSize(int sampleRateInHz, int channelConfig, int audioFormat)
MODE_STREAM
mode.
The size is an estimate because it does not consider either the route or the sink,
since neither is known yet. Note that this size doesn't
guarantee a smooth playback under load, and higher values should be chosen according to
the expected frequency at which the buffer will be refilled with additional data to play.
For example, if you intend to dynamically set the source sample rate of an AudioTrack
to a higher value than the initial source sample rate, be sure to configure the buffer size
based on the highest planned sample rate.sampleRateInHz
- the source sample rate expressed in Hz.
AudioFormat.SAMPLE_RATE_UNSPECIFIED
is not permitted.channelConfig
- describes the configuration of the audio channels.
See AudioFormat.CHANNEL_OUT_MONO
and
AudioFormat.CHANNEL_OUT_STEREO
audioFormat
- the format in which the audio data is represented.
See AudioFormat.ENCODING_PCM_16BIT
and
AudioFormat.ENCODING_PCM_8BIT
,
and AudioFormat.ENCODING_PCM_FLOAT
.ERROR_BAD_VALUE
if an invalid parameter was passed,
or ERROR
if unable to query for output properties,
or the minimum buffer size expressed in bytes.public int getAudioSessionId()
public boolean getTimestamp(AudioTimestamp timestamp)
If you need to track timestamps during initial warmup or after a routing or mode change, you should request a new timestamp periodically until the reported timestamps show that the frame position is advancing, or until it becomes clear that timestamps are unavailable for this route.
After the clock is advancing at a stable rate, query for a new timestamp approximately once every 10 seconds to once per minute. Calling this method more often is inefficient. It is also counter-productive to call this method more often than recommended, because the short-term differences between successive timestamp reports are not meaningful. If you need a high-resolution mapping between frame position and presentation time, consider implementing that at application level, based on low-resolution timestamps.
The audio data at the returned position may either already have been presented, or may have not yet been presented but is committed to be presented. It is not possible to request the time corresponding to a particular position, or to request the (fractional) position corresponding to a particular time. If you need such features, consider implementing them at application level.
timestamp
- a reference to a non-null AudioTimestamp instance allocated
and owned by caller.getPlaybackHeadPosition()
.
However, it may be useful to continue to query for
timestamps occasionally, to recover after a route change.public int getTimestampWithStatus(AudioTimestamp timestamp)
Same as getTimestamp(AudioTimestamp)
but with a more useful return code.
timestamp
- a reference to a non-null AudioTimestamp instance allocated
and owned by caller.SUCCESS
if a timestamp is available
ERROR_WOULD_BLOCK
if called in STOPPED or FLUSHED state, or if called
immediately after start/ACTIVE, when the number of frames consumed is less than the
overall hardware latency to physical output. In WOULD_BLOCK cases, one might poll
again, or use getPlaybackHeadPosition()
, or use 0 position and current time
for the timestamp.
ERROR_DEAD_OBJECT
if the AudioTrack is not valid anymore and
needs to be recreated.
ERROR_INVALID_OPERATION
if current route does not support
timestamps. In this case, the approximate frame position can be obtained
using getPlaybackHeadPosition()
.
The AudioTimestamp instance is filled in with a position in frame units, together
with the estimated time when that frame was presented or is committed to
be presented.public void setPlaybackPositionUpdateListener(AudioTrack.OnPlaybackPositionUpdateListener listener)
listener
- public void setPlaybackPositionUpdateListener(AudioTrack.OnPlaybackPositionUpdateListener listener, Handler handler)
listener
- handler
- the Handler that will receive the event notification messages.@Deprecated public int setStereoVolume(float leftGain, float rightGain)
setVolume(float)
instead, as it
more gracefully scales down to mono, and up to multi-channel content beyond stereo.Gain values are clamped to the closed interval [0.0, max] where
max is the value of getMaxVolume()
.
A value of 0.0 results in zero gain (silence), and
a value of 1.0 means unity gain (signal unchanged).
The default value is 1.0 meaning unity gain.
The word "volume" in the API name is historical; this is actually a linear gain.
leftGain
- output gain for the left channel.rightGain
- output gain for the right channelSUCCESS
,
ERROR_INVALID_OPERATION
public int setVolume(float gain)
Gain values are clamped to the closed interval [0.0, max] where
max is the value of getMaxVolume()
.
A value of 0.0 results in zero gain (silence), and
a value of 1.0 means unity gain (signal unchanged).
The default value is 1.0 meaning unity gain.
This API is preferred over setStereoVolume(float, float)
, as it
more gracefully scales down to mono, and up to multi-channel content beyond stereo.
The word "volume" in the API name is historical; this is actually a linear gain.
gain
- output gain for all channels.SUCCESS
,
ERROR_INVALID_OPERATION
public int setPlaybackRate(int sampleRateInHz)
AudioTrack(int, int, int, int, int, int)
constructor),
not the original sampling rate of the
content. For example, setting it to half the sample rate of the content will cause the
playback to last twice as long, but will also result in a pitch shift down by one octave.
The valid sample rate range is from 1 Hz to twice the value returned by
getNativeOutputSampleRate(int)
.
Use setPlaybackParams(PlaybackParams)
for speed control.
This method may also be used to repurpose an existing AudioTrack
for playback of content of differing sample rate,
but with identical encoding and channel mask.
sampleRateInHz
- the sample rate expressed in HzSUCCESS
, ERROR_BAD_VALUE
,
ERROR_INVALID_OPERATION
public void setPlaybackParams(PlaybackParams params)
AudioTrack
is streaming
(see MODE_STREAM
) and the
buffer size is too small. For speeds greater than 1.0f, the AudioTrack
buffer
on configuration must be larger than the speed multiplied by the minimum size
getMinBufferSize(int, int, int)
) to allow proper playback.params
- see PlaybackParams
. In particular,
speed, pitch, and audio mode should be set.IllegalArgumentException
- if the parameters are invalid or not accepted.IllegalStateException
- if track is not initialized.public int setNotificationMarkerPosition(int markerInFrames)
markerInFrames
- marker position in wrapping frame units similar to
getPlaybackHeadPosition()
, or zero to disable the marker.
To set a marker at a position which would appear as zero due to wraparound,
a workaround is to use a non-zero position near zero, such as -1 or 1.SUCCESS
, ERROR_BAD_VALUE
,
ERROR_INVALID_OPERATION
public int setPositionNotificationPeriod(int periodInFrames)
periodInFrames
- update period expressed in frames.
Zero period means no position updates. A negative period is not allowed.SUCCESS
, ERROR_INVALID_OPERATION
public int setPlaybackHeadPosition(int positionInFrames)
MODE_STATIC
mode.positionInFrames
- playback head position within buffer, expressed in frames.
Zero corresponds to start of buffer.
The position must not be greater than the buffer size in frames, or negative.
Though this method and getPlaybackHeadPosition()
have similar names,
the position values have different meanings.
Build.VERSION_CODES.M
,
the looping is first disabled and then the position is set.
For earlier API levels, the behavior is unspecified.SUCCESS
, ERROR_BAD_VALUE
,
ERROR_INVALID_OPERATION
public int setLoopPoints(int startInFrames, int endInFrames, int loopCount)
MODE_STATIC
mode.startInFrames
- loop start marker expressed in frames.
Zero corresponds to start of buffer.
The start marker must not be greater than or equal to the buffer size in frames, or negative.endInFrames
- loop end marker expressed in frames.
The total buffer size in frames corresponds to end of buffer.
The end marker must not be greater than the buffer size in frames.
For looping, the end marker must not be less than or equal to the start marker,
but to disable looping
it is permitted for start marker, end marker, and loop count to all be 0.
If any input parameters are out of range, this method returns ERROR_BAD_VALUE
.
If the loop period (endInFrames - startInFrames) is too small for the implementation to
support,
ERROR_BAD_VALUE
is returned.
The loop range is the interval [startInFrames, endInFrames).
Build.VERSION_CODES.M
, the position is left unchanged,
unless it is greater than or equal to the loop end marker, in which case
it is forced to the loop start marker.
For earlier API levels, the effect on position is unspecified.loopCount
- the number of times the loop is looped; must be greater than or equal to -1.
A value of -1 means infinite looping, and 0 disables looping.
A value of positive N means to "loop" (go back) N times. For example,
a value of one means to play the region two times in total.SUCCESS
, ERROR_BAD_VALUE
,
ERROR_INVALID_OPERATION
@Deprecated protected void setState(int state)
state
- the state of the AudioTrack instancepublic void play() throws IllegalStateException
If track's creation mode is MODE_STATIC
, you must have called one of
the write methods (write(byte[], int, int)
, write(byte[], int, int, int)
,
write(short[], int, int)
, write(short[], int, int, int)
,
write(float[], int, int, int)
, or write(ByteBuffer, int, int)
) prior to
play().
If the mode is MODE_STREAM
, you can optionally prime the data path prior to
calling play(), by writing up to bufferSizeInBytes
(from constructor).
If you don't call write() first, or if you call write() but with an insufficient amount of
data, then the track will be in underrun state at play(). In this case,
playback will not actually start playing until the data path is filled to a
device-specific minimum level. This requirement for the path to be filled
to a minimum level is also true when resuming audio playback after calling stop().
Similarly the buffer will need to be filled up again after
the track underruns due to failure to call write() in a timely manner with sufficient data.
For portability, an application should prime the data path to the maximum allowed
by writing data until the write() method returns a short transfer count.
This allows play() to start immediately, and reduces the chance of underrun.
IllegalStateException
- if the track isn't properly initializedpublic void stop() throws IllegalStateException
MODE_STREAM
mode, audio will stop playing
after the last buffer that was written has been played. For an immediate stop, use
pause()
, followed by flush()
to discard audio data that hasn't been played
back yet.IllegalStateException
public void pause() throws IllegalStateException
play()
will play
this data back. See flush()
to discard this data.IllegalStateException
public void flush()
MODE_STREAM
.
write(byte[], int, int)
with sizeInBytes
less than or equal to the total buffer size
may return a short actual transfer count.public int write(byte[] audioData, int offsetInBytes, int sizeInBytes)
AudioFormat.ENCODING_PCM_8BIT
to correspond to the data in the array.
The format can be AudioFormat.ENCODING_PCM_16BIT
, but this is deprecated.
In streaming mode, the write will normally block until all the data has been enqueued for playback, and will return a full transfer count. However, if the track is stopped or paused on entry, or another thread interrupts the write by calling stop or pause, or an I/O error occurs during the write, then the write may return a short transfer count.
In static buffer mode, copies the data to the buffer starting at offset 0. Note that the actual playback of this data might occur after this function returns.
audioData
- the array that holds the data to play.offsetInBytes
- the offset expressed in bytes in audioData where the data to write
starts.
Must not be negative, or cause the data access to go out of bounds of the array.sizeInBytes
- the number of bytes to write in audioData after the offset.
Must not be negative, or cause the data access to go out of bounds of the array.ERROR_INVALID_OPERATION
if the track isn't properly initializedERROR_BAD_VALUE
if the parameters don't resolve to valid data and indexesERROR_DEAD_OBJECT
if the AudioTrack is not valid anymore and
needs to be recreated. The dead object error code is not returned if some data was
successfully transferred. In this case, the error is returned at the next write()ERROR
in case of other errorwrite(byte[], int, int, int)
with writeMode
set to WRITE_BLOCKING
.public int write(byte[] audioData, int offsetInBytes, int sizeInBytes, int writeMode)
AudioFormat.ENCODING_PCM_8BIT
to correspond to the data in the array.
The format can be AudioFormat.ENCODING_PCM_16BIT
, but this is deprecated.
In streaming mode, the blocking behavior depends on the write mode. If the write mode is
WRITE_BLOCKING
, the write will normally block until all the data has been enqueued
for playback, and will return a full transfer count. However, if the write mode is
WRITE_NON_BLOCKING
, or the track is stopped or paused on entry, or another thread
interrupts the write by calling stop or pause, or an I/O error
occurs during the write, then the write may return a short transfer count.
In static buffer mode, copies the data to the buffer starting at offset 0, and the write mode is ignored. Note that the actual playback of this data might occur after this function returns.
audioData
- the array that holds the data to play.offsetInBytes
- the offset expressed in bytes in audioData where the data to write
starts.
Must not be negative, or cause the data access to go out of bounds of the array.sizeInBytes
- the number of bytes to write in audioData after the offset.
Must not be negative, or cause the data access to go out of bounds of the array.writeMode
- one of WRITE_BLOCKING
, WRITE_NON_BLOCKING
. It has no
effect in static mode.
WRITE_BLOCKING
, the write will block until all data has been written
to the audio sink.
WRITE_NON_BLOCKING
, the write will return immediately after
queuing as much audio data for playback as possible without blocking.ERROR_INVALID_OPERATION
if the track isn't properly initializedERROR_BAD_VALUE
if the parameters don't resolve to valid data and indexesERROR_DEAD_OBJECT
if the AudioTrack is not valid anymore and
needs to be recreated. The dead object error code is not returned if some data was
successfully transferred. In this case, the error is returned at the next write()ERROR
in case of other errorpublic int write(short[] audioData, int offsetInShorts, int sizeInShorts)
AudioFormat.ENCODING_PCM_16BIT
to correspond to the data in the array.
In streaming mode, the write will normally block until all the data has been enqueued for playback, and will return a full transfer count. However, if the track is stopped or paused on entry, or another thread interrupts the write by calling stop or pause, or an I/O error occurs during the write, then the write may return a short transfer count.
In static buffer mode, copies the data to the buffer starting at offset 0. Note that the actual playback of this data might occur after this function returns.
audioData
- the array that holds the data to play.offsetInShorts
- the offset expressed in shorts in audioData where the data to play
starts.
Must not be negative, or cause the data access to go out of bounds of the array.sizeInShorts
- the number of shorts to read in audioData after the offset.
Must not be negative, or cause the data access to go out of bounds of the array.ERROR_INVALID_OPERATION
if the track isn't properly initializedERROR_BAD_VALUE
if the parameters don't resolve to valid data and indexesERROR_DEAD_OBJECT
if the AudioTrack is not valid anymore and
needs to be recreated. The dead object error code is not returned if some data was
successfully transferred. In this case, the error is returned at the next write()ERROR
in case of other errorwrite(short[], int, int, int)
with writeMode
set to WRITE_BLOCKING
.public int write(short[] audioData, int offsetInShorts, int sizeInShorts, int writeMode)
AudioFormat.ENCODING_PCM_16BIT
to correspond to the data in the array.
In streaming mode, the blocking behavior depends on the write mode. If the write mode is
WRITE_BLOCKING
, the write will normally block until all the data has been enqueued
for playback, and will return a full transfer count. However, if the write mode is
WRITE_NON_BLOCKING
, or the track is stopped or paused on entry, or another thread
interrupts the write by calling stop or pause, or an I/O error
occurs during the write, then the write may return a short transfer count.
In static buffer mode, copies the data to the buffer starting at offset 0. Note that the actual playback of this data might occur after this function returns.
audioData
- the array that holds the data to write.offsetInShorts
- the offset expressed in shorts in audioData where the data to write
starts.
Must not be negative, or cause the data access to go out of bounds of the array.sizeInShorts
- the number of shorts to read in audioData after the offset.
Must not be negative, or cause the data access to go out of bounds of the array.writeMode
- one of WRITE_BLOCKING
, WRITE_NON_BLOCKING
. It has no
effect in static mode.
WRITE_BLOCKING
, the write will block until all data has been written
to the audio sink.
WRITE_NON_BLOCKING
, the write will return immediately after
queuing as much audio data for playback as possible without blocking.ERROR_INVALID_OPERATION
if the track isn't properly initializedERROR_BAD_VALUE
if the parameters don't resolve to valid data and indexesERROR_DEAD_OBJECT
if the AudioTrack is not valid anymore and
needs to be recreated. The dead object error code is not returned if some data was
successfully transferred. In this case, the error is returned at the next write()ERROR
in case of other errorpublic int write(float[] audioData, int offsetInFloats, int sizeInFloats, int writeMode)
AudioFormat.ENCODING_PCM_FLOAT
to correspond to the data in the array.
In streaming mode, the blocking behavior depends on the write mode. If the write mode is
WRITE_BLOCKING
, the write will normally block until all the data has been enqueued
for playback, and will return a full transfer count. However, if the write mode is
WRITE_NON_BLOCKING
, or the track is stopped or paused on entry, or another thread
interrupts the write by calling stop or pause, or an I/O error
occurs during the write, then the write may return a short transfer count.
In static buffer mode, copies the data to the buffer starting at offset 0, and the write mode is ignored. Note that the actual playback of this data might occur after this function returns.
audioData
- the array that holds the data to write.
The implementation does not clip for sample values within the nominal range
[-1.0f, 1.0f], provided that all gains in the audio pipeline are
less than or equal to unity (1.0f), and in the absence of post-processing effects
that could add energy, such as reverb. For the convenience of applications
that compute samples using filters with non-unity gain,
sample values +3 dB beyond the nominal range are permitted.
However such values may eventually be limited or clipped, depending on various gains
and later processing in the audio path. Therefore applications are encouraged
to provide samples values within the nominal range.offsetInFloats
- the offset, expressed as a number of floats,
in audioData where the data to write starts.
Must not be negative, or cause the data access to go out of bounds of the array.sizeInFloats
- the number of floats to write in audioData after the offset.
Must not be negative, or cause the data access to go out of bounds of the array.writeMode
- one of WRITE_BLOCKING
, WRITE_NON_BLOCKING
. It has no
effect in static mode.
WRITE_BLOCKING
, the write will block until all data has been written
to the audio sink.
WRITE_NON_BLOCKING
, the write will return immediately after
queuing as much audio data for playback as possible without blocking.ERROR_INVALID_OPERATION
if the track isn't properly initializedERROR_BAD_VALUE
if the parameters don't resolve to valid data and indexesERROR_DEAD_OBJECT
if the AudioTrack is not valid anymore and
needs to be recreated. The dead object error code is not returned if some data was
successfully transferred. In this case, the error is returned at the next write()ERROR
in case of other errorpublic int write(ByteBuffer audioData, int sizeInBytes, int writeMode)
In streaming mode, the blocking behavior depends on the write mode. If the write mode is
WRITE_BLOCKING
, the write will normally block until all the data has been enqueued
for playback, and will return a full transfer count. However, if the write mode is
WRITE_NON_BLOCKING
, or the track is stopped or paused on entry, or another thread
interrupts the write by calling stop or pause, or an I/O error
occurs during the write, then the write may return a short transfer count.
In static buffer mode, copies the data to the buffer starting at offset 0, and the write mode is ignored. Note that the actual playback of this data might occur after this function returns.
audioData
- the buffer that holds the data to write, starting at the position reported
by audioData.position()
.
audioData.position()
) will
have been advanced to reflect the amount of data that was successfully written to
the AudioTrack.sizeInBytes
- number of bytes to write. It is recommended but not enforced
that the number of bytes requested be a multiple of the frame size (sample size in
bytes multiplied by the channel count).
audioData.remaining()
, but cannot exceed it.writeMode
- one of WRITE_BLOCKING
, WRITE_NON_BLOCKING
. It has no
effect in static mode.
WRITE_BLOCKING
, the write will block until all data has been written
to the audio sink.
WRITE_NON_BLOCKING
, the write will return immediately after
queuing as much audio data for playback as possible without blocking.ERROR_INVALID_OPERATION
if the track isn't properly initializedERROR_BAD_VALUE
if the parameters don't resolve to valid data and indexesERROR_DEAD_OBJECT
if the AudioTrack is not valid anymore and
needs to be recreated. The dead object error code is not returned if some data was
successfully transferred. In this case, the error is returned at the next write()ERROR
in case of other errorpublic int write(ByteBuffer audioData, int sizeInBytes, int writeMode, long timestamp)
audioData
- the buffer that holds the data to write, starting at the position reported
by audioData.position()
.
audioData.position()
) will
have been advanced to reflect the amount of data that was successfully written to
the AudioTrack.sizeInBytes
- number of bytes to write. It is recommended but not enforced
that the number of bytes requested be a multiple of the frame size (sample size in
bytes multiplied by the channel count).
audioData.remaining()
, but cannot exceed it.writeMode
- one of WRITE_BLOCKING
, WRITE_NON_BLOCKING
.
WRITE_BLOCKING
, the write will block until all data has been written
to the audio sink.
WRITE_NON_BLOCKING
, the write will return immediately after
queuing as much audio data for playback as possible without blocking.timestamp
- The timestamp of the first decodable audio frame in the provided audioData.ERROR_INVALID_OPERATION
if the track isn't properly initializedERROR_BAD_VALUE
if the parameters don't resolve to valid data and indexesERROR_DEAD_OBJECT
if the AudioTrack is not valid anymore and
needs to be recreated. The dead object error code is not returned if some data was
successfully transferred. In this case, the error is returned at the next write()ERROR
in case of other errorpublic int reloadStaticData()
MODE_STATIC
.
As of Build.VERSION_CODES.M
, also resets the value returned by
getPlaybackHeadPosition()
to zero.
For earlier API levels, the reset behavior is unspecified.
Use setPlaybackHeadPosition(int)
with a zero position
if the reset of getPlaybackHeadPosition()
is not needed.
SUCCESS
, ERROR_BAD_VALUE
,
ERROR_INVALID_OPERATION
public int attachAuxEffect(int effectId)
setAuxEffectSendLevel(float)
.
After creating an auxiliary effect (e.g.
EnvironmentalReverb
), retrieve its ID with
AudioEffect.getId()
and use it when calling
this method to attach the audio track to the effect.
To detach the effect from the audio track, call this method with a null effect id.
effectId
- system wide unique id of the effect to attachSUCCESS
,
ERROR_INVALID_OPERATION
, ERROR_BAD_VALUE
public int setAuxEffectSendLevel(float level)
attachAuxEffect(int)
. Effect levels
are clamped to the closed interval [0.0, max] where
max is the value of getMaxVolume()
.
A value of 0.0 results in no effect, and a value of 1.0 is full send.
By default the send level is 0.0f, so even if an effect is attached to the player this method must be called for the effect to be applied.
Note that the passed level value is a linear scalar. UI controls should be scaled logarithmically: the gain applied by audio framework ranges from -72dB to at least 0dB, so an appropriate conversion from linear UI input x to level is: x == 0 -> level = 0 0 < x <= R -> level = 10^(72*(x-R)/20/R)
level
- linear send levelSUCCESS
,
ERROR_INVALID_OPERATION
, ERROR
public boolean setPreferredDevice(AudioDeviceInfo deviceInfo)
AudioDeviceInfo
object) to route
the output from this AudioTrack.setPreferredDevice
in interface AudioRouting
deviceInfo
- The AudioDeviceInfo
specifying the audio sink.
If deviceInfo is null, default routing is restored.AudioDeviceInfo
is non-null and
does not correspond to a valid audio output device.public AudioDeviceInfo getPreferredDevice()
setPreferredDevice(android.media.AudioDeviceInfo)
. Note that this
is not guaranteed to correspond to the actual device being used for playback.getPreferredDevice
in interface AudioRouting
public AudioDeviceInfo getRoutedDevice()
AudioDeviceInfo
identifying the current routing of this AudioTrack.
Note: The query is only valid if the AudioTrack is currently playing. If it is not,
getRoutedDevice()
will return null.getRoutedDevice
in interface AudioRouting
public void addOnRoutingChangedListener(AudioRouting.OnRoutingChangedListener listener, Handler handler)
AudioRouting.OnRoutingChangedListener
to receive notifications of routing
changes on this AudioTrack.addOnRoutingChangedListener
in interface AudioRouting
listener
- The AudioRouting.OnRoutingChangedListener
interface to receive
notifications of rerouting events.handler
- Specifies the Handler
object for the thread on which to execute
the callback. If null
, the Handler
associated with the main
Looper
will be used.public void removeOnRoutingChangedListener(AudioRouting.OnRoutingChangedListener listener)
AudioRouting.OnRoutingChangedListener
which has been previously added
to receive rerouting notifications.removeOnRoutingChangedListener
in interface AudioRouting
listener
- The previously added AudioRouting.OnRoutingChangedListener
interface
to remove.@Deprecated public void addOnRoutingChangedListener(AudioTrack.OnRoutingChangedListener listener, Handler handler)
AudioRouting.OnRoutingChangedListener
class instead.AudioTrack.OnRoutingChangedListener
to receive notifications of routing changes
on this AudioTrack.listener
- The AudioTrack.OnRoutingChangedListener
interface to receive notifications
of rerouting events.handler
- Specifies the Handler
object for the thread on which to execute
the callback. If null
, the Handler
associated with the main
Looper
will be used.@Deprecated public void removeOnRoutingChangedListener(AudioTrack.OnRoutingChangedListener listener)
AudioRouting.OnRoutingChangedListener
class instead.AudioTrack.OnRoutingChangedListener
which has been previously added
to receive rerouting notifications.listener
- The previously added AudioTrack.OnRoutingChangedListener
interface to remove.public final void native_release()