@Implements(value=android.media.AudioTrack.class, looseSignatures=true) public class ShadowAudioTrack extends Object
AudioTrack
. Only a couple methods are supported,
other methods are expected run through the real class. The two AudioTrack.WriteMode
are treated the
same.Modifier and Type | Class | Description |
---|---|---|
static interface |
ShadowAudioTrack.OnAudioDataWrittenListener |
Listeners to be notified when data is written to an
AudioTrack via AudioTrack.write(ByteBuffer, int, int) |
Modifier and Type | Field | Description |
---|---|---|
protected static int |
DEFAULT_MIN_BUFFER_SIZE |
Constructor | Description |
---|---|
ShadowAudioTrack() |
Modifier and Type | Method | Description |
---|---|---|
static void |
addAudioDataListener(ShadowAudioTrack.OnAudioDataWrittenListener listener) |
Registers an
ShadowAudioTrack.OnAudioDataWrittenListener to the ShadowAudioTrack . |
protected void |
flush() |
|
protected int |
getPlaybackHeadPosition() |
|
protected static int |
native_get_FCC_8() |
|
protected static int |
native_get_min_buff_size(int sampleRateInHz,
int channelConfig,
int audioFormat) |
Returns a predefined or default minimum buffer size.
|
protected int |
native_write_byte(byte[] audioData,
int offsetInBytes,
int sizeInBytes,
int format,
boolean isBlocking) |
Always return the number of bytes to write.
|
static void |
removeAudioDataListener(ShadowAudioTrack.OnAudioDataWrittenListener listener) |
Removes an
ShadowAudioTrack.OnAudioDataWrittenListener from the ShadowAudioTrack . |
static void |
resetTest() |
|
static void |
setMinBufferSize(int bufferSize) |
In the real class, the minimum buffer size is estimated from audio sample rate and other
factors.
|
protected int |
write(ByteBuffer audioData,
int sizeInBytes,
int writeMode) |
Always return the number of bytes to write except with invalid parameters.
|
protected static final int DEFAULT_MIN_BUFFER_SIZE
public static void setMinBufferSize(int bufferSize)
native_get_min_buff_size(int, int, int)
,
instead letting users set the minimum for the expected audio sample. Usually higher sample rate
requires bigger buffer size.@Implementation(minSdk=24, maxSdk=28) protected static int native_get_FCC_8()
@Implementation protected static int native_get_min_buff_size(int sampleRateInHz, int channelConfig, int audioFormat)
@Implementation(minSdk=23) protected final int native_write_byte(byte[] audioData, int offsetInBytes, int sizeInBytes, int format, boolean isBlocking)
AudioTrack.WRITE_BLOCKING
@Implementation(minSdk=21) protected int write(ByteBuffer audioData, int sizeInBytes, int writeMode)
AudioTrack.WRITE_BLOCKING
@Implementation protected int getPlaybackHeadPosition()
@Implementation protected void flush()
public static void addAudioDataListener(ShadowAudioTrack.OnAudioDataWrittenListener listener)
ShadowAudioTrack.OnAudioDataWrittenListener
to the ShadowAudioTrack
.listener
- The ShadowAudioTrack.OnAudioDataWrittenListener
to be registered.public static void removeAudioDataListener(ShadowAudioTrack.OnAudioDataWrittenListener listener)
ShadowAudioTrack.OnAudioDataWrittenListener
from the ShadowAudioTrack
.listener
- The ShadowAudioTrack.OnAudioDataWrittenListener
to be removed.@Resetter public static void resetTest()