AudioTrack.Write AudioTrack.Write Method

Definition

Overloads

Write(Single[], Int32, Int32, WriteMode) Write(Single[], Int32, Int32, WriteMode)

Writes the audio data to the audio sink for playback (streaming mode), or copies audio data for later playback (static buffer mode).

Write(Int16[], Int32, Int32, WriteMode) Write(Int16[], Int32, Int32, WriteMode)
Write(ByteBuffer, Int32, WriteMode, Int64) Write(ByteBuffer, Int32, WriteMode, Int64)
Write(Byte[], Int32, Int32, WriteMode) Write(Byte[], Int32, Int32, WriteMode)
Write(Byte[], Int32, Int32) Write(Byte[], Int32, Int32)

Writes the audio data to the audio sink for playback (streaming mode), or copies audio data for later playback (static buffer mode).

Write(ByteBuffer, Int32, WriteMode) Write(ByteBuffer, Int32, WriteMode)

Writes the audio data to the audio sink for playback (streaming mode), or copies audio data for later playback (static buffer mode).

Write(Int16[], Int32, Int32) Write(Int16[], Int32, Int32)

Writes the audio data to the audio sink for playback (streaming mode), or copies audio data for later playback (static buffer mode).

Write(Single[], Int32, Int32, WriteMode) Write(Single[], Int32, Int32, WriteMode)

Writes the audio data to the audio sink for playback (streaming mode), or copies audio data for later playback (static buffer mode).

[Android.Runtime.Register("write", "([FIII)I", "GetWrite_arrayFIIIHandler", ApiSince=21)]
public virtual int Write (float[] audioData, int offsetInFloats, int sizeInFloats, Android.Media.WriteMode writeMode);
abstract member Write : single[] * int * int * Android.Media.WriteMode -> int
override this.Write : single[] * int * int * Android.Media.WriteMode -> int

Parameters

audioData
Single[]

the array that holds the data to play. 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
Int32 Int32

the offset, expressed as a number of floats, in audioData where the data to play starts.

sizeInFloats
Int32 Int32

the number of floats to read in audioData after the offset.

writeMode
WriteMode WriteMode

one of Android.Media.AudioTrack.WRITE_BLOCKING, Android.Media.AudioTrack.WRITE_NON_BLOCKING. It has no effect in static mode.
With Android.Media.AudioTrack.WRITE_BLOCKING, the write will block until all data has been written to the audio sink.
With Android.Media.AudioTrack.WRITE_NON_BLOCKING, the write will return immediately after queuing as much audio data for playback as possible without blocking.

Returns

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Write(Int16[], Int32, Int32, WriteMode) Write(Int16[], Int32, Int32, WriteMode)

[Android.Runtime.Register("write", "([SIII)I", "GetWrite_arraySIIIHandler", ApiSince=23)]
public virtual int Write (short[] audioData, int offsetInShorts, int sizeInShorts, Android.Media.WriteMode writeMode);
abstract member Write : int16[] * int * int * Android.Media.WriteMode -> int
override this.Write : int16[] * int * int * Android.Media.WriteMode -> int

Parameters

audioData
Int16[]
offsetInShorts
Int32 Int32
sizeInShorts
Int32 Int32
writeMode
WriteMode WriteMode

Returns

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Write(ByteBuffer, Int32, WriteMode, Int64) Write(ByteBuffer, Int32, WriteMode, Int64)

[Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;IIJ)I", "GetWrite_Ljava_nio_ByteBuffer_IIJHandler", ApiSince=23)]
public virtual int Write (Java.Nio.ByteBuffer audioData, int sizeInBytes, Android.Media.WriteMode writeMode, long timestamp);
abstract member Write : Java.Nio.ByteBuffer * int * Android.Media.WriteMode * int64 -> int
override this.Write : Java.Nio.ByteBuffer * int * Android.Media.WriteMode * int64 -> int

Parameters

sizeInBytes
Int32 Int32
writeMode
WriteMode WriteMode
timestamp
Int64 Int64

Returns

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Write(Byte[], Int32, Int32, WriteMode) Write(Byte[], Int32, Int32, WriteMode)

[Android.Runtime.Register("write", "([BIII)I", "GetWrite_arrayBIIIHandler", ApiSince=23)]
public virtual int Write (byte[] audioData, int offsetInBytes, int sizeInBytes, Android.Media.WriteMode writeMode);
abstract member Write : byte[] * int * int * Android.Media.WriteMode -> int
override this.Write : byte[] * int * int * Android.Media.WriteMode -> int

Parameters

audioData
Byte[]
offsetInBytes
Int32 Int32
sizeInBytes
Int32 Int32
writeMode
WriteMode WriteMode

Returns

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Write(Byte[], Int32, Int32) Write(Byte[], Int32, Int32)

Writes the audio data to the audio sink for playback (streaming mode), or copies audio data for later playback (static buffer mode).

[Android.Runtime.Register("write", "([BII)I", "GetWrite_arrayBIIHandler")]
public virtual int Write (byte[] audioData, int offsetInBytes, int sizeInBytes);
abstract member Write : byte[] * int * int -> int
override this.Write : byte[] * int * int -> int

Parameters

audioData
Byte[]

the array that holds the data to play.

offsetInBytes
Int32 Int32

the offset expressed in bytes in audioData where the data to play starts.

sizeInBytes
Int32 Int32

the number of bytes to read in audioData after the offset.

Returns

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Write(ByteBuffer, Int32, WriteMode) Write(ByteBuffer, Int32, WriteMode)

Writes the audio data to the audio sink for playback (streaming mode), or copies audio data for later playback (static buffer mode).

[Android.Runtime.Register("write", "(Ljava/nio/ByteBuffer;II)I", "GetWrite_Ljava_nio_ByteBuffer_IIHandler", ApiSince=21)]
public virtual int Write (Java.Nio.ByteBuffer audioData, int sizeInBytes, Android.Media.WriteMode writeMode);
abstract member Write : Java.Nio.ByteBuffer * int * Android.Media.WriteMode -> int
override this.Write : Java.Nio.ByteBuffer * int * Android.Media.WriteMode -> int

Parameters

audioData
ByteBuffer ByteBuffer

the buffer that holds the data to play, starting at the position reported by audioData.position().
Note that upon return, the buffer position (audioData.position()) will have been advanced to reflect the amount of data that was successfully written to the AudioTrack.

sizeInBytes
Int32 Int32

number of bytes to write.
Note this may differ from audioData.remaining(), but cannot exceed it.

writeMode
WriteMode WriteMode

one of Android.Media.AudioTrack.WRITE_BLOCKING, Android.Media.AudioTrack.WRITE_NON_BLOCKING. It has no effect in static mode.
With Android.Media.AudioTrack.WRITE_BLOCKING, the write will block until all data has been written to the audio sink.
With Android.Media.AudioTrack.WRITE_NON_BLOCKING, the write will return immediately after queuing as much audio data for playback as possible without blocking.

Returns

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Write(Int16[], Int32, Int32) Write(Int16[], Int32, Int32)

Writes the audio data to the audio sink for playback (streaming mode), or copies audio data for later playback (static buffer mode).

[Android.Runtime.Register("write", "([SII)I", "GetWrite_arraySIIHandler")]
public virtual int Write (short[] audioData, int offsetInShorts, int sizeInShorts);
abstract member Write : int16[] * int * int -> int
override this.Write : int16[] * int * int -> int

Parameters

audioData
Int16[]

the array that holds the data to play.

offsetInShorts
Int32 Int32

the offset expressed in shorts in audioData where the data to play starts.

sizeInShorts
Int32 Int32

the number of shorts to read in audioData after the offset.

Returns

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to