Best code examples for Android AudioTrack class (android.media.AudioTrack)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android AudioTrack class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android AudioTrack examples from Open Source projects
Examples using Android AudioTrack release method:
This code example shows how to use the following methods: release, stop
141:	oTrack.stop(); 
142:	oTrack.release(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: release, stop
118:	mAudio.stop(); 
119:	mAudio.release(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: release, stop
165:	try { audiotrack.stop(); } catch(Exception e) { e.printStackTrace(); } 
166:	audiotrack.release(); 
Full Snippet Info
7
CodeRank
Examples using Android AudioTrack play method:
This code example shows how to use the following methods: play
102:	AudioTrack.MODE_STREAM ); 
103:	mAudio.play(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: play, setStereoVolume
243:	audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT, minBufferSize, AudioTrack.MODE_STREAM); 
-
246:	audioTrack.setStereoVolume(audioVolume, audioVolume); 
-
248:	audioTrack.play(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: play, write
157:	audiotrack.play(); 
158:	audiotrack.write(audio, 0, audio.length); 
Full Snippet Info
6
CodeRank
Examples using Android AudioTrack getAudioFormat method:
This code example shows how to use the following methods: getAudioFormat, getChannelCount, getSampleRate, getState
64:	track.getSampleRate() == rate && 
65:	track.getAudioFormat() == format && 
66:	track.getChannelCount() == channels) 
Full Snippet Info
7
CodeRank
Examples using Android AudioTrack getPlayState method:
This code example shows how to use the following methods: getPlayState, play, write
285:	if (AudioTrack.PLAYSTATE_PLAYING != mAudioTrack.getPlayState()) { 
286:	mAudioTrack.play(); 
-
288:	int size = mAudioTrack.write(buf, 0, buf.length); 
Full Snippet Info
7
CodeRank
Examples using Android AudioTrack getState method:
This code example shows how to use the following methods: getState, play, release, setPlaybackRate, write
584:	AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, 
-
589:	track.write(data, 0, data.length); 
590:	track.write(data, 0, data.length); 
591:	assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); 
592:	track.play(); 
593:	assertTrue(TEST_NAME, track.setPlaybackRate(2*outputSR) == AudioTrack.SUCCESS); 
-
595:	track.release(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: getState, play, write
63:	if (mAudioTrack.getState() == AudioTrack.STATE_UNINITIALIZED) 
-
65:	if (mAudioTrack.write(audioData, 0, bufferSize) != bufferSize) { 
-
68:	mAudioTrack.play(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: getState, play, write
63:	if (mAudioTrack.getState() == AudioTrack.STATE_UNINITIALIZED) 
-
65:	if (mAudioTrack.write(audioData, 0, bufferSize) != bufferSize) { 
-
68:	mAudioTrack.play(); 
Full Snippet Info
6
CodeRank
Examples using Android AudioTrack flush method:
This code example shows how to use the following methods: flush, play, release, write
100:	AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 
-
104:	audioTrack.write(generatedSnd, 0, generatedSnd.length); 
105:	audioTrack.play(); 
106:	audioTrack.flush(); 
107:	audioTrack.release(); 
Full Snippet Info
6
CodeRank
Examples using Android AudioTrack stop method:
This code example shows how to use the following methods: play, stop, write
47:	audioTrack.play(); 
48:	audioTrack.write(soundBuffer, 0, minBufferSize); 
49:	audioTrack.stop(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: release, stop
187:	audioTrack.stop(); 
188:	audioTrack.release(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: release, stop
95:	mAudio.stop(); 
96:	mAudio.release(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: getNotificationMarkerPosition, getPlaybackHeadPosition, getPlaybackRate, getPositionNotificationPeriod, getSampleRate
809:	_at = new AudioTrack( 
-
821:	+ _at.getNotificationMarkerPosition()); 
822:	WebrtcLog("Play head pos = " + _at.getPlaybackHeadPosition()); 
-
824:	+ _at.getPositionNotificationPeriod()); 
825:	WebrtcLog("Playback rate = " + _at.getPlaybackRate()); 
826:	WebrtcLog("Sample rate = " + _at.getSampleRate()); 
Full Snippet Info
6
CodeRank
Examples for other Android AudioTrack methods:
Related Android AudioTrack Questions & Answers:
AudioTrack Class Overview
The AudioTrack class manages and plays a single audio resource for Java applications. It allows streaming of PCM audio buffers to the audio sink for playback. This is achieved by "pushing" the data to the AudioTrack object using one of the write(byte[], int, int) and write(short[], int, int) methods.

An AudioTrack instance can operate under two modes: static or streaming. In Streaming mode, the application writes a continuous stream of data to the AudioTrack, using one of the write() methods. These are blocking and return when the data has been transferred from the Java layer to the native layer and queued for playback. The streaming mode is most useful when playing blocks of audio data that for instance are: too big to fit in memory because of the duration of the sound to play, too big to fit in memory because of the characteristics of the audio data (high sampling rate, bits per sample ...) received or generated while previously queued audio is playing. The static mode should be chosen when dealing with short sounds that fit in memory and that need to be played with the smallest latency possible. The static mode will therefore be preferred for UI and game sounds that are played often, and with the smallest overhead possible. Upon creation, an AudioTrack object initializes its associated audio buffer. The size of this buffer, specified during the construction, determines how long an AudioTrack can play before running out of data. For an AudioTrack using the static mode, this size is the maximum size of the sound that can be played from it. For the streaming mode, data will be written to the audio sink in chunks of sizes less than or equal to the total buffer size. AudioTrack is not final an...
Methods
  • flush
    Flushes the audio data currently queued for playback.
  • getPlayState
    Returns the playback state of the AudioTrack instance.
  • getSampleRate
    Returns the configured audio data sample rate in Hz
  • getState
    Returns the state of the AudioTrack instance.
  • pause
    Pauses the playback of the audio data.
  • play
    Starts playing an AudioTrack.
  • release
    Releases the native AudioTrack resources.
  • reloadStaticData
    Notifies the native resource to reuse the audio data already loaded in the native layer, that is to rewind to start of buffer.
  • setStereoVolume
    Sets the specified left/right output volume values on the AudioTrack.
  • stop
    Stops playing the audio data.
  • write
    Writes the audio data to the audio sink for playback (streaming mode), or copies audio data for later playback (static buffer mode).