Package org.robolectric.shadows
Class ShadowAudioTrack
java.lang.Object
org.robolectric.shadows.ShadowAudioTrack
@Implements(value=android.media.AudioTrack.class, looseSignatures=true) public class ShadowAudioTrack extends Object
Implementation of a couple methods in
AudioTrack
. Only a couple methods are supported,
other methods are expected run through the real class. The two AudioTrack.WriteMode
are treated the
same.-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ShadowAudioTrack.OnAudioDataWrittenListener
Listeners to be notified when data is written to anAudioTrack
viaAudioTrack.write(ByteBuffer, int, int)
-
Field Summary
Fields Modifier and Type Field Description protected static int
DEFAULT_MIN_BUFFER_SIZE
-
Constructor Summary
Constructors Constructor Description ShadowAudioTrack()
-
Method Summary
Modifier and Type Method Description static void
addAudioDataListener(ShadowAudioTrack.OnAudioDataWrittenListener listener)
Registers anShadowAudioTrack.OnAudioDataWrittenListener
to theShadowAudioTrack
.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 anShadowAudioTrack.OnAudioDataWrittenListener
from theShadowAudioTrack
.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.
-
Field Details
-
DEFAULT_MIN_BUFFER_SIZE
protected static final int DEFAULT_MIN_BUFFER_SIZE- See Also:
- Constant Field Values
-
-
Constructor Details
-
ShadowAudioTrack
public ShadowAudioTrack()
-
-
Method Details
-
setMinBufferSize
public static void setMinBufferSize(int bufferSize)In the real class, the minimum buffer size is estimated from audio sample rate and other factors. We do not provide such estimation innative_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. -
native_get_FCC_8
-
native_get_min_buff_size
@Implementation protected static int native_get_min_buff_size(int sampleRateInHz, int channelConfig, int audioFormat)Returns a predefined or default minimum buffer size. Audio format and config are neglected. -
native_write_byte
@Implementation(minSdk=23) protected final int native_write_byte(byte[] audioData, int offsetInBytes, int sizeInBytes, int format, boolean isBlocking)Always return the number of bytes to write. This method returns immedidately even withAudioTrack.WRITE_BLOCKING
-
write
@Implementation(minSdk=21) protected int write(ByteBuffer audioData, int sizeInBytes, int writeMode)Always return the number of bytes to write except with invalid parameters. Assumes AudioTrack is already initialized (object properly created). Do not block even if AudioTrack in offload mode is in STOPPING play state. This method returns immediately even withAudioTrack.WRITE_BLOCKING
-
getPlaybackHeadPosition
-
flush
-
addAudioDataListener
Registers anShadowAudioTrack.OnAudioDataWrittenListener
to theShadowAudioTrack
.- Parameters:
listener
- TheShadowAudioTrack.OnAudioDataWrittenListener
to be registered.
-
removeAudioDataListener
Removes anShadowAudioTrack.OnAudioDataWrittenListener
from theShadowAudioTrack
.- Parameters:
listener
- TheShadowAudioTrack.OnAudioDataWrittenListener
to be removed.
-
resetTest
-