AudioTrack

Class of android.media · AudioTrack.java · Android's reference

public class AudioTrack

PCM output. The Java side has no host audio device, so a track plays silence in real time: the play head moves at the sample rate, a streaming write blocks while its buffer is full, and a static track ends at its last frame.

Fields

public static final int MODE_STATIC = 0 source
public static final int MODE_STREAM = 1 source
public static final int STATE_UNINITIALIZED = 0 source
public static final int STATE_INITIALIZED = 1 source
public static final int STATE_NO_STATIC_DATA = 2 source
public static final int PLAYSTATE_STOPPED = 1 source
public static final int PLAYSTATE_PAUSED = 2 source
public static final int PLAYSTATE_PLAYING = 3 source
public static final int SUCCESS = 0 source
public static final int ERROR = -1 source
public static final int ERROR_BAD_VALUE = -2 source
public static final int ERROR_INVALID_OPERATION = -3 source
public static final int ERROR_DEAD_OBJECT = -6 source
public static final int WRITE_BLOCKING = 0 source
public static final int WRITE_NON_BLOCKING = 1 source

Constructors

public AudioTrack(int streamType, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes, int mode) deprecated source
public AudioTrack(int streamType, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes, int mode, int sessionId) deprecated source

Methods

public static int getMinBufferSize(int sampleRateInHz, int channelConfig, int audioFormat) source

20 ms of frames, the least that the host mixer takes.

public static float getMinVolume() source
public static float getMaxVolume() source
public static int getNativeOutputSampleRate(int streamType) source
public int getState() source
public int getStreamType() source
public int getSampleRate() source
public int getPlaybackRate() source
public int getAudioFormat() source
public int getChannelConfiguration() source
public int getChannelCount() source
public int getAudioSessionId() source
public int getBufferSizeInFrames() source
public int getBufferCapacityInFrames() source
public synchronized int getPlayState() source
public synchronized int getPlaybackHeadPosition() source
public synchronized void play() source
public synchronized void pause() source
public synchronized void stop() source
public synchronized void flush() source

The frames written and not played yet are dropped, outside play.

public void release() source
public int setVolume(float gain) source
public int setStereoVolume(float leftGain, float rightGain) deprecated source
public int write(byte[] audioData, int offsetInBytes, int sizeInBytes) source
public int write(byte[] audioData, int offsetInBytes, int sizeInBytes, int writeMode) source
public int write(short[] audioData, int offsetInShorts, int sizeInShorts) source
public int write(float[] audioData, int offsetInFloats, int sizeInFloats, int writeMode) source
public int write(ByteBuffer audioData, int sizeInBytes, int writeMode) source

Made from ScarletNX's Sail at 166ad3910f80. The framework is ScarletNX's (GPL-3.0-or-later); the parts that follow the Android Open Source Project's sources (Apache-2.0) say so in their files.