Press on the image to return to the main documentation page.
AudioTrack
Written by Steve Laming
List of types:
AudioTrack
AudioTrack
Events:
None
Members:
Af_PCM_16
As
Int
Af_PCM_8
As
Int
AttachAuxEffect
(
effectID
As
Int
)
As
Int
Ch_Conf_Mono
As
Int
Ch_Conf_Stereo
As
Int
Error
As
Int
Error_Bad_Value
As
Int
Error_Invalid_Operation
As
Int
Flush
GetAudioFormat
As
Int
GetAudioSessionID
As
Int
GetChannelConfiguration
As
Int
GetChannelCount
As
Int
GetMaxVolume
As
Float
GetMinBuffersize
(
sampleRate
As
Int
,
channelConfig
As
Int
,
audioFormat
As
Int
)
As
Int
GetMinVolume
As
Float
GetNativeOutputSampleRate
(
streamType
As
Int
)
As
Int
GetNotificationMarkerPosition
As
Int
GetPlaybackHeadPosition
As
Int
GetPlaybackRate
As
Int
GetPlayState
As
Int
GetPositionNotificationPeriod
As
Int
GetSampleRate
As
Int
GetState
As
Int
GetStreamType
As
Int
Initialize
(
streamType
As
Int
,
sampleRateHz
As
Int
,
channelConfig
As
Int
,
audioFormat
As
Int
,
bufferSize
As
Int
,
mode
As
Int
)
Initialize2
(
streamType
As
Int
,
sampleRateHz
As
Int
,
channelConfig
As
Int
,
audioFormat
As
Int
,
bufferSize
As
Int
,
mode
As
Int
,
sessionId
As
Int
)
IsInitialized
As
Boolean
Mode_Static
As
Int
Mode_Stream
As
Int
Pause
Play
Playstate_Paused
As
Int
Playstate_Playing
As
Int
Playstate_Stopped
As
Int
Release
ReloadStaticData
As
Int
SetAuxEffectSendLevel
(
level
As
Float
)
As
Int
SetLoopPoints
(
startInFrames
As
Int
,
endInFrames
As
Int
,
loopCount
As
Int
)
As
Int
SetNotificationMarkerPosition
(
markerInFrames
As
Int
)
As
Int
SetPlaybackHeadPosition
(
positionInFrames
As
Int
)
As
Int
SetPlaybackRate
(
sampleRateInHz
As
Int
)
As
Int
SetPositionNotificationPeriod
(
periodInFrames
As
Int
)
As
Int
SetStereoVolume
(
leftVolume
As
Float
,
rightVolume
As
Float
)
As
Int
State_Initialized
As
Int
State_No_Static_Data
As
Int
State_UnInitialized
As
Int
Stop
Stream_Alarm
As
Int
Stream_Music
As
Int
Stream_Notification
As
Int
Stream_Ring
As
Int
Stream_System
As
Int
Stream_Voice_Call
As
Int
Success
As
Int
WriteByte
(
audioData
()
As
Byte
,
offsetInBytes
As
Int
,
sizeInBytes
As
Int
)
As
Int
WriteShort
(
audioData
()
As
Short
,
offsetInShorts
As
Int
,
sizeInShorts
As
Int
)
As
Int
Members description:
Af_PCM_16
As
Int
Af_PCM_8
As
Int
AttachAuxEffect
(
effectID
As
Int
)
As
Int
Attaches an auxiliary effect to the audio track.
Requires API Level 9
Ch_Conf_Mono
As
Int
Ch_Conf_Stereo
As
Int
Error
As
Int
Error_Bad_Value
As
Int
Error_Invalid_Operation
As
Int
Flush
Flushes the audio data currently queued for playback. Any data that has not been played back will be discarded.
GetAudioFormat
As
Int
Returns the configured audio data format. See ENCODING_PCM_16BIT and ENCODING_PCM_8BIT.
GetAudioSessionID
As
Int
Returns the audio session ID.
GetChannelConfiguration
As
Int
Returns the configured channel configuration. See CHANNEL_OUT_MONO and CHANNEL_OUT_STEREO.
GetChannelCount
As
Int
Returns the configured number of channels.
GetMaxVolume
As
Float
Returns the maximum valid volume value. Volume values set above this one will be clamped at this value.
GetMinBuffersize
(
sampleRate
As
Int
,
channelConfig
As
Int
,
audioFormat
As
Int
)
As
Int
Returns the minimum buffer size required for the successful creation of an AudioTrack object
to be created in the MODE_STREAM mode. Note that this size doesn't guarantee a smooth playback
under load, and higher values should be chosen according to the expected frequency at which the
buffer will be refilled with additional data to play.
returns :
-2 if an invalid parameter was passed
-1 if the implementation was unable to query the hardware for its output properties,
or the minimum buffer size expressed in bytes.
GetMinVolume
As
Float
Returns the minimum valid volume value. Volume values set under this one will be clamped at this value.
GetNativeOutputSampleRate
(
streamType
As
Int
)
As
Int
Returns the hardware output sample rate
GetNotificationMarkerPosition
As
Int
Returns marker position expressed in frames.
GetPlaybackHeadPosition
As
Int
Returns the playback head position expressed in frames
GetPlaybackRate
As
Int
Returns the current playback rate in Hz.
GetPlayState
As
Int
Returns the playback state of the AudioTrack instance.
1 = PlayState Stopped
2 = PlayState Paused
3 = PlayState Playing
GetPositionNotificationPeriod
As
Int
Returns the notification update period expressed in frames.
GetSampleRate
As
Int
Returns the configured audio data sample rate in Hz
GetState
As
Int
Returns the state of the AudioTrack instance. This is useful after the AudioTrack
instance has been created to check if it was initialized properly. This ensures that
the appropriate hardware resources have been acquired.
GetStreamType
As
Int
Returns the type of audio stream this AudioTrack is configured for.
Compare the result against STREAM_VOICE_CALL, STREAM_SYSTEM, STREAM_RING, STREAM_MUSIC
or STREAM_ALARM
Initialize
(
streamType
As
Int
,
sampleRateHz
As
Int
,
channelConfig
As
Int
,
audioFormat
As
Int
,
bufferSize
As
Int
,
mode
As
Int
)
Initialize AudioTrack:
StreamType - the type of the audio stream. See STREAM_VOICE_CALL, STREAM_SYSTEM, STREAM_RING, STREAM_MUSIC and STREAM_ALARM
SampleRate - 44100 is standard and should work on all devices,22050,16000.11025 and 8000 may work on some
Channel config - Mono or Stereo depending on available hardware, Mono is the safe option
Audio format, 8 or 16 bit encoding
Buffer size - the total size (in bytes) of the buffer where audio data is written to during the recording.
Mode - streaming or static buffer. See MODE_STATIC and MODE_STREAM
See getMinBufferSize(int, int, int) to determine the minimum required buffer size for the successful
creation of an AudioTrack instance. Using values smaller than getMinBufferSize() will
result in an initialization failure.
To use Marker callback you need to create a sub called Audiotrack_MarkerReached in your Main Module and
SetNotificationMarkerPosition
To use Periodic callback you need to create a sub called Audiotrack_PeriodPassed in your Main Module and
and SetPositionNotificationPeriod
Initialize2
(
streamType
As
Int
,
sampleRateHz
As
Int
,
channelConfig
As
Int
,
audioFormat
As
Int
,
bufferSize
As
Int
,
mode
As
Int
,
sessionId
As
Int
)
Initialize2 AudioTrack:
StreamType - the type of the audio stream. See STREAM_VOICE_CALL, STREAM_SYSTEM, STREAM_RING, STREAM_MUSIC and STREAM_ALARM
SampleRate - 44100 is standard and should work on all devices,22050,16000.11025 and 8000 may work on some
Channel config - Mono or Stereo depending on available hardware, Mono is the safe option
Audio format, 8 or 16 bit encoding
Buffer size - the total size (in bytes) of the buffer where audio data is written to during the recording.
Mode - streaming or static buffer. See MODE_STATIC and MODE_STREAM
sessionID - Id of audio session the AudioTrack must be attached to
See getMinBufferSize(int, int, int) to determine the minimum required buffer size for the successful
creation of an AudioTrack instance. Using values smaller than getMinBufferSize() will
result in an initialization failure.
To use Marker callback you need to create a sub called Audiotrack_MarkerReached in your Main Module and
SetNotificationMarkerPosition
To use Periodic callback you need to create a sub called Audiotrack_PeriodPassed in your Main Module and
and SetPositionNotificationPeriod
IsInitialized
As
Boolean
Mode_Static
As
Int
Mode_Stream
As
Int
Pause
Pauses the playback of the audio data. Data that has not been played back will not be discarded.
Subsequent calls to play() will play this data back.
Play
Starts playing an AudioTrack.
Playstate_Paused
As
Int
Playstate_Playing
As
Int
Playstate_Stopped
As
Int
Release
Releases the native AudioTrack resources.
ReloadStaticData
As
Int
Notifies the native resource to reuse the audio data already loaded in the native layer.
This call is only valid with AudioTrack instances that don't use the streaming model.
SetAuxEffectSendLevel
(
level
As
Float
)
As
Int
Sets the send level of the audio track to the attached auxiliary effect attachAuxEffect(int).
The level value range is 0 to 1.0. By default the send level is 0, so even if an effect is attached
to the player this method must be called for the effect to be applied.
SetLoopPoints
(
startInFrames
As
Int
,
endInFrames
As
Int
,
loopCount
As
Int
)
As
Int
Sets the loop points and the loop count. The loop can be infinite.
startInFrames - loop start marker expressed in frames
endInFrames - loop end marker expressed in frames
loopCount - the number of times the loop is looped. A value of -1 means infinite looping.
SetNotificationMarkerPosition
(
markerInFrames
As
Int
)
As
Int
Sets the position of the notification marker.
SetPlaybackHeadPosition
(
positionInFrames
As
Int
)
As
Int
Sets the playback head position. The track must be stopped for the position to be changed.
SetPlaybackRate
(
sampleRateInHz
As
Int
)
As
Int
Sets the playback sample rate for this track. The valid sample rate range if from 1Hz to
twice the value returned by getNativeOutputSampleRate(int).
SetPositionNotificationPeriod
(
periodInFrames
As
Int
)
As
Int
Sets the period for the periodic notification event.
SetStereoVolume
(
leftVolume
As
Float
,
rightVolume
As
Float
)
As
Int
Sets the specified left/right output volume values on the AudioTrack. Values are clamped to
the (getMinVolume(), getMaxVolume()) interval if outside this range.
State_Initialized
As
Int
State_No_Static_Data
As
Int
State_UnInitialized
As
Int
Stop
Stops playing the audio data.
Stream_Alarm
As
Int
Stream_Music
As
Int
Stream_Notification
As
Int
Stream_Ring
As
Int
Stream_System
As
Int
Stream_Voice_Call
As
Int
Success
As
Int
WriteByte
(
audioData
()
As
Byte
,
offsetInBytes
As
Int
,
sizeInBytes
As
Int
)
As
Int
Writes the audio data to the audio hardware for playback. Will block until all
data has been written to the audio mixer. Note that the actual playback of this
data might occur after this function returns. This function is thread safe with respect
to stop() calls, in which case all of the specified data might not be written to the mixer.
WriteShort
(
audioData
()
As
Short
,
offsetInShorts
As
Int
,
sizeInShorts
As
Int
)
As
Int
Writes the audio data to the audio hardware for playback. Will block until all
data has been written to the audio mixer. Note that the actual playback of this
data might occur after this function returns. This function is thread safe with respect
to stop() calls, in which case all of the specified data might not be written to the mixer.
Top