共用方式為


AudioTrack Constructors

Definition

Overloads

AudioTrack(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

AudioTrack(AudioAttributes, AudioFormat, Int32, AudioTrackMode, Int32)

Class constructor with AudioAttributes and AudioFormat.

AudioTrack(Stream, Int32, ChannelConfiguration, Encoding, Int32, AudioTrackMode)
Obsolete.

Class constructor.

AudioTrack(Stream, Int32, ChannelOut, Encoding, Int32, AudioTrackMode)

Class constructor.

AudioTrack(Stream, Int32, ChannelConfiguration, Encoding, Int32, AudioTrackMode, Int32)
Obsolete.

Class constructor with audio session.

AudioTrack(Stream, Int32, ChannelOut, Encoding, Int32, AudioTrackMode, Int32)

Class constructor with audio session.

AudioTrack(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

protected AudioTrack (IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer);
new Android.Media.AudioTrack : nativeint * Android.Runtime.JniHandleOwnership -> Android.Media.AudioTrack

Parameters

javaReference
IntPtr

nativeint

A IntPtrcontaining a Java Native Interface (JNI) object reference.

transfer
JniHandleOwnership

A JniHandleOwnershipindicating how to handle javaReference

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

AudioTrack(AudioAttributes, AudioFormat, Int32, AudioTrackMode, Int32)

Class constructor with AudioAttributes and AudioFormat.

[Android.Runtime.Register(".ctor", "(Landroid/media/AudioAttributes;Landroid/media/AudioFormat;III)V", "")]
public AudioTrack (Android.Media.AudioAttributes? attributes, Android.Media.AudioFormat? format, int bufferSizeInBytes, Android.Media.AudioTrackMode mode, int sessionId);
[<Android.Runtime.Register(".ctor", "(Landroid/media/AudioAttributes;Landroid/media/AudioFormat;III)V", "")>]
new Android.Media.AudioTrack : Android.Media.AudioAttributes * Android.Media.AudioFormat * int * Android.Media.AudioTrackMode * int -> Android.Media.AudioTrack

Parameters

attributes
AudioAttributes

a non-null AudioAttributes instance.

format
AudioFormat

a non-null AudioFormat instance describing the format of the data that will be played through this AudioTrack. See AudioFormat.Builder for configuring the audio format parameters such as encoding, channel mask and sample rate.

bufferSizeInBytes
Int32

the total size (in bytes) of the internal buffer where audio data is read from for playback. This should be a nonzero multiple of the frame size in bytes. <p> If the track's creation mode is #MODE_STATIC, this is the maximum length sample, or audio clip, that can be played by this instance. <p> If the track's creation mode is #MODE_STREAM, this should be the desired buffer size for the AudioTrack to satisfy the application's latency requirements. If bufferSizeInBytes is less than the minimum buffer size for the output sink, it is increased to the minimum buffer size. The method #getBufferSizeInFrames() returns the actual size in frames of the buffer created, which determines the minimum frequency to write to the streaming AudioTrack to avoid underrun. See #getMinBufferSize(int, int, int) to determine the estimated minimum buffer size for an AudioTrack instance in streaming mode.

mode
AudioTrackMode

streaming or static buffer. See #MODE_STATIC and #MODE_STREAM.

sessionId
Int32

ID of audio session the AudioTrack must be attached to, or AudioManager#AUDIO_SESSION_ID_GENERATE if the session isn't known at construction time. See also AudioManager#generateAudioSessionId() to obtain a session ID before construction.

Attributes

Exceptions

Remarks

Class constructor with AudioAttributes and AudioFormat.

Java documentation for android.media.AudioTrack.AudioTrack(android.media.AudioAttributes, android.media.AudioFormat, int, int, int).

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

AudioTrack(Stream, Int32, ChannelConfiguration, Encoding, Int32, AudioTrackMode)

Caution

ChannelConfiguration is obsolete. Please use another overload with ChannelOut instead

Class constructor.

[System.Obsolete("ChannelConfiguration is obsolete. Please use another overload with ChannelOut instead")]
public AudioTrack (Android.Media.Stream streamType, int sampleRateInHz, Android.Media.ChannelConfiguration channelConfig, Android.Media.Encoding audioFormat, int bufferSizeInBytes, Android.Media.AudioTrackMode mode);
[<System.Obsolete("ChannelConfiguration is obsolete. Please use another overload with ChannelOut instead")>]
new Android.Media.AudioTrack : Android.Media.Stream * int * Android.Media.ChannelConfiguration * Android.Media.Encoding * int * Android.Media.AudioTrackMode -> Android.Media.AudioTrack

Parameters

streamType
Stream
sampleRateInHz
Int32
channelConfig
ChannelConfiguration
audioFormat
Encoding
bufferSizeInBytes
Int32
Attributes

Exceptions

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

AudioTrack(Stream, Int32, ChannelOut, Encoding, Int32, AudioTrackMode)

Class constructor.

[Android.Runtime.Register(".ctor", "(IIIIII)V", "")]
public AudioTrack (Android.Media.Stream streamType, int sampleRateInHz, Android.Media.ChannelOut channelConfig, Android.Media.Encoding audioFormat, int bufferSizeInBytes, Android.Media.AudioTrackMode mode);
[<Android.Runtime.Register(".ctor", "(IIIIII)V", "")>]
new Android.Media.AudioTrack : Android.Media.Stream * int * Android.Media.ChannelOut * Android.Media.Encoding * int * Android.Media.AudioTrackMode -> Android.Media.AudioTrack

Parameters

streamType
Stream

the type of the audio stream. See AudioManager#STREAM_VOICE_CALL, AudioManager#STREAM_SYSTEM, AudioManager#STREAM_RING, AudioManager#STREAM_MUSIC, AudioManager#STREAM_ALARM, and AudioManager#STREAM_NOTIFICATION.

sampleRateInHz
Int32

the initial source sample rate expressed in Hz. AudioFormat#SAMPLE_RATE_UNSPECIFIED means to use a route-dependent value which is usually the sample rate of the sink. #getSampleRate() can be used to retrieve the actual sample rate chosen.

channelConfig
ChannelOut

describes the configuration of the audio channels. See AudioFormat#CHANNEL_OUT_MONO and AudioFormat#CHANNEL_OUT_STEREO

audioFormat
Encoding

the format in which the audio data is represented. See AudioFormat#ENCODING_PCM_16BIT, AudioFormat#ENCODING_PCM_8BIT, and AudioFormat#ENCODING_PCM_FLOAT.

bufferSizeInBytes
Int32

the total size (in bytes) of the internal buffer where audio data is read from for playback. This should be a nonzero multiple of the frame size in bytes. <p> If the track's creation mode is #MODE_STATIC, this is the maximum length sample, or audio clip, that can be played by this instance. <p> If the track's creation mode is #MODE_STREAM, this should be the desired buffer size for the AudioTrack to satisfy the application's latency requirements. If bufferSizeInBytes is less than the minimum buffer size for the output sink, it is increased to the minimum buffer size. The method #getBufferSizeInFrames() returns the actual size in frames of the buffer created, which determines the minimum frequency to write to the streaming AudioTrack to avoid underrun. See #getMinBufferSize(int, int, int) to determine the estimated minimum buffer size for an AudioTrack instance in streaming mode.

mode
AudioTrackMode

streaming or static buffer. See #MODE_STATIC and #MODE_STREAM

Attributes

Exceptions

Remarks

Class constructor.

This member is deprecated. use Builder or #AudioTrack(AudioAttributes, AudioFormat, int, int, int) to specify the AudioAttributes instead of the stream type which is only for volume control.

Java documentation for android.media.AudioTrack.AudioTrack(int, int, int, int, int, int).

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

AudioTrack(Stream, Int32, ChannelConfiguration, Encoding, Int32, AudioTrackMode, Int32)

Caution

ChannelConfiguration is obsolete. Please use another overload with ChannelOut instead

Class constructor with audio session.

[System.Obsolete("ChannelConfiguration is obsolete. Please use another overload with ChannelOut instead")]
public AudioTrack (Android.Media.Stream streamType, int sampleRateInHz, Android.Media.ChannelConfiguration channelConfig, Android.Media.Encoding audioFormat, int bufferSizeInBytes, Android.Media.AudioTrackMode mode, int sessionId);
[<System.Obsolete("ChannelConfiguration is obsolete. Please use another overload with ChannelOut instead")>]
new Android.Media.AudioTrack : Android.Media.Stream * int * Android.Media.ChannelConfiguration * Android.Media.Encoding * int * Android.Media.AudioTrackMode * int -> Android.Media.AudioTrack

Parameters

streamType
Stream
sampleRateInHz
Int32
channelConfig
ChannelConfiguration
audioFormat
Encoding
bufferSizeInBytes
Int32
sessionId
Int32
Attributes

Exceptions

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

AudioTrack(Stream, Int32, ChannelOut, Encoding, Int32, AudioTrackMode, Int32)

Class constructor with audio session.

[Android.Runtime.Register(".ctor", "(IIIIIII)V", "")]
public AudioTrack (Android.Media.Stream streamType, int sampleRateInHz, Android.Media.ChannelOut channelConfig, Android.Media.Encoding audioFormat, int bufferSizeInBytes, Android.Media.AudioTrackMode mode, int sessionId);
[<Android.Runtime.Register(".ctor", "(IIIIIII)V", "")>]
new Android.Media.AudioTrack : Android.Media.Stream * int * Android.Media.ChannelOut * Android.Media.Encoding * int * Android.Media.AudioTrackMode * int -> Android.Media.AudioTrack

Parameters

streamType
Stream

the type of the audio stream. See AudioManager#STREAM_VOICE_CALL, AudioManager#STREAM_SYSTEM, AudioManager#STREAM_RING, AudioManager#STREAM_MUSIC, AudioManager#STREAM_ALARM, and AudioManager#STREAM_NOTIFICATION.

sampleRateInHz
Int32

the initial source sample rate expressed in Hz. AudioFormat#SAMPLE_RATE_UNSPECIFIED means to use a route-dependent value which is usually the sample rate of the sink.

channelConfig
ChannelOut

describes the configuration of the audio channels. See AudioFormat#CHANNEL_OUT_MONO and AudioFormat#CHANNEL_OUT_STEREO

audioFormat
Encoding

the format in which the audio data is represented. See AudioFormat#ENCODING_PCM_16BIT and AudioFormat#ENCODING_PCM_8BIT, and AudioFormat#ENCODING_PCM_FLOAT.

bufferSizeInBytes
Int32

the total size (in bytes) of the internal buffer where audio data is read from for playback. This should be a nonzero multiple of the frame size in bytes. <p> If the track's creation mode is #MODE_STATIC, this is the maximum length sample, or audio clip, that can be played by this instance. <p> If the track's creation mode is #MODE_STREAM, this should be the desired buffer size for the AudioTrack to satisfy the application's latency requirements. If bufferSizeInBytes is less than the minimum buffer size for the output sink, it is increased to the minimum buffer size. The method #getBufferSizeInFrames() returns the actual size in frames of the buffer created, which determines the minimum frequency to write to the streaming AudioTrack to avoid underrun. You can write data into this buffer in smaller chunks than this size. See #getMinBufferSize(int, int, int) to determine the estimated minimum buffer size for an AudioTrack instance in streaming mode.

mode
AudioTrackMode

streaming or static buffer. See #MODE_STATIC and #MODE_STREAM

sessionId
Int32

Id of audio session the AudioTrack must be attached to

Attributes

Exceptions

Remarks

Class constructor with audio session. Use this constructor when the AudioTrack must be attached to a particular audio session. The primary use of the audio session ID is to associate audio effects to a particular instance of AudioTrack: if an audio session ID is provided when creating an AudioEffect, this effect will be applied only to audio tracks and media players in the same session and not to the output mix. When an AudioTrack is created without specifying a session, it will create its own session which can be retrieved by calling the #getAudioSessionId() method. If a non-zero session ID is provided, this AudioTrack will share effects attached to this session with all other media players or audio tracks in the same session, otherwise a new session will be created for this track if none is supplied.

This member is deprecated. use Builder or #AudioTrack(AudioAttributes, AudioFormat, int, int, int) to specify the AudioAttributes instead of the stream type which is only for volume control.

Java documentation for android.media.AudioTrack.AudioTrack(int, int, int, int, int, int, int).

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