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 inAudioTrack. Only a couple methods are supported, other methods are expected run through the real class. The twoAudioTrack.WriteModeare treated the same.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceShadowAudioTrack.OnAudioDataWrittenListenerListeners to be notified when data is written to anAudioTrackviaAudioTrack.write(ByteBuffer, int, int)
-
Field Summary
Fields Modifier and Type Field Description protected static intDEFAULT_MIN_BUFFER_SIZE
-
Constructor Summary
Constructors Constructor Description ShadowAudioTrack()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddAudioDataListener(ShadowAudioTrack.OnAudioDataWrittenListener listener)Registers anShadowAudioTrack.OnAudioDataWrittenListenerto theShadowAudioTrack.protected voidflush()protected intgetPlaybackHeadPosition()protected static intnative_get_FCC_8()protected static intnative_get_min_buff_size(int sampleRateInHz, int channelConfig, int audioFormat)Returns a predefined or default minimum buffer size.protected intnative_write_byte(byte[] audioData, int offsetInBytes, int sizeInBytes, int format, boolean isBlocking)Always return the number of bytes to write.static voidremoveAudioDataListener(ShadowAudioTrack.OnAudioDataWrittenListener listener)Removes anShadowAudioTrack.OnAudioDataWrittenListenerfrom theShadowAudioTrack.static voidresetTest()static voidsetMinBufferSize(int bufferSize)In the real class, the minimum buffer size is estimated from audio sample rate and other factors.protected intwrite(ByteBuffer audioData, int sizeInBytes, int writeMode)Always return the number of bytes to write except with invalid parameters.
-
-
-
Field Detail
-
DEFAULT_MIN_BUFFER_SIZE
protected static final int DEFAULT_MIN_BUFFER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
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
@Implementation(minSdk=24, maxSdk=28) protected static int 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
@Implementation protected int getPlaybackHeadPosition()
-
flush
@Implementation protected void flush()
-
addAudioDataListener
public static void addAudioDataListener(ShadowAudioTrack.OnAudioDataWrittenListener listener)
Registers anShadowAudioTrack.OnAudioDataWrittenListenerto theShadowAudioTrack.- Parameters:
listener- TheShadowAudioTrack.OnAudioDataWrittenListenerto be registered.
-
removeAudioDataListener
public static void removeAudioDataListener(ShadowAudioTrack.OnAudioDataWrittenListener listener)
Removes anShadowAudioTrack.OnAudioDataWrittenListenerfrom theShadowAudioTrack.- Parameters:
listener- TheShadowAudioTrack.OnAudioDataWrittenListenerto be removed.
-
resetTest
@Resetter public static void resetTest()
-
-