AudioTrack flush - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for AudioTrack flush method.

This code example shows how to use the following methods:flush, stop
			track.play();
	} 
 
	static void audioStop() { 
		if (track != null) {
			track.stop();
			track.flush();
		} 
	} 
 
	static void audioPause() { 
		if (track != null)
			track.pause();
	} 
 
	static void audioPlay(byte[] data, int size) {
		if (track != null)
			track.write(data, 0, size);
	} 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:flush, play, release, write
    } 
 
    private void playSound() { 
 
//        Log.i("BFV_samples","" + numSamples ) ; 
        AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
                sampleRate, AudioFormat.CHANNEL_OUT_MONO,
                AudioFormat.ENCODING_PCM_16BIT, numSamples,
                AudioTrack.MODE_STATIC);
        audioTrack.write(generatedSnd, 0, generatedSnd.length);
        audioTrack.play();
        audioTrack.flush();
        audioTrack.release();
 
    } 
} 
 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:flush
    @CalledByNative 
    private void flush() { 
        mMediaCodec.flush();
        mFlushed = true;
        if (mAudioTrack != null) {
            mAudioTrack.flush();
        } 
    } 
 
    @CalledByNative 
    private void stop() { 
        mMediaCodec.stop();
        if (mAudioTrack != null) {
            mAudioTrack.pause();
        } 
    } 
 
    @CalledByNative 
    private int getOutputHeight() { 
        return mMediaCodec.getOutputFormat().getInteger(MediaFormat.KEY_HEIGHT);
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:flush, play, write
 
public class PlaySound { 
 
	public static void playBa(final int sampleRate,
			final byte[] baSoundByteArray, final OnPlaySoundComplete opsc) {
		final AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
				sampleRate, AudioFormat.CHANNEL_OUT_MONO,
				AudioFormat.ENCODING_PCM_16BIT, baSoundByteArray.length,
				AudioTrack.MODE_STATIC);
		Log.i(PlaySound.class.getName(), "PlaySound - Size of the stream : "
				+ baSoundByteArray.length);
		audioTrack.write(baSoundByteArray, 0, baSoundByteArray.length);
		audioTrack.flush();
		audioTrack.play();
 
		new Thread() {
			@Override 
			public void run() { 
				int lastFrame = -1;
				while (lastFrame != audioTrack.getPlaybackHeadPosition()) {
					lastFrame = audioTrack.getPlaybackHeadPosition();
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:flush, getPlaybackHeadPosition, getState, play, release
        final int TEST_MODE = AudioTrack.MODE_STREAM;
        final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
         
        //-------- initialization -------------- 
        int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
        AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, 
                minBuffSize, TEST_MODE);
        byte data[] = new byte[minBuffSize/2];
        //--------    test        -------------- 
        assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
        track.write(data, 0, data.length);
        track.write(data, 0, data.length);
        track.play();
        Thread.sleep(100);
        track.stop();
        track.flush();
        log(TEST_NAME, "position ="+ track.getPlaybackHeadPosition());
        assertTrue(TEST_NAME, track.getPlaybackHeadPosition() == 0);
        //-------- tear down      -------------- 
        track.release();

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:flush, getState, pause, release
		} 
	} 
 
	public void stop() 
	{ 
		if(audioTrack.getState() == AudioTrack.STATE_INITIALIZED)
		{ 
			setIsPlaying(false); 
			audioTrack.pause();
			audioTrack.flush();
			audioTrack.release();
		} 
	} 
	public void setFreq(int freq)
	{ 
		frequency = freq;
	} 
	public int getFreq() 
	{ 
		return frequency;
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:flush, getPlayState, getState, stop
                    + ".startPlay(): Failed to initialise speakers."); 
        } 
    } 
 
    protected void stopPlay() { 
        if ((_speaker != null) && (_speaker.getState() == AudioTrack.STATE_INITIALIZED)) {
            if (_speaker.getPlayState() != AudioTrack.PLAYSTATE_STOPPED) {
                _speaker.flush();
                _speaker.stop();
            } 
            AndroidLog.getLog().debug( 
                    this.getClass().getSimpleName()
                    + ".stopPlay(): speaker stopped"); 
            _speakerFrames = 0;
            _hasSpeakerStarted = false;
 
            if (_me != null) {
                Thread tspeaker = _me;
                _me = null;
                try { 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:flush, release, stop
		// })).start(); 
 
	} 
 
	public void stopSound() { 
		audioTrack.flush();
		audioTrack.stop();
		audioTrack.release();
		// if (audioTrack.getPlayState() == audioTrack.PLAYSTATE_PLAYING) { 
		// audioTrack.stop(); 
		// } 
	} 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:flush, write
			audioin.read(buffer);
			audioin.close();
		} catch (IOException ex) {
			Log.e(TAG, "prepare failed: " + ex.getMessage());
		} 
		at = new AudioTrack(AudioManager.STREAM_MUSIC, DEFAULT_RATE, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_DEFAULT, fileLength, AudioTrack.MODE_STATIC);
		at.write(buffer, 0, fileLength);
		at.flush();
	} 
 
	public void play(double speed) {
		// Otherwise it plays the sound twice the first time 
		if (!first) {
			at.stop();
			at.reloadStaticData();
		} 
		at.setPlaybackRate((int) (DEFAULT_RATE * speed));
		first = false;
		at.play();
	} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:flush, write
			audioin.read(buffer);
			audioin.close();
		} catch (IOException ex) {
			Log.e(TAG, "prepare failed: " + ex.getMessage());
		} 
		at = new AudioTrack(AudioManager.STREAM_MUSIC, DEFAULT_RATE, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_DEFAULT, fileLength, AudioTrack.MODE_STATIC);
		at.write(buffer, 0, fileLength);
		at.flush();
	} 
 
	public void play(double speed) {
		// Otherwise it plays the sound twice the first time 
		if (!first) {
			at.stop();
			at.reloadStaticData();
		} 
		at.setPlaybackRate((int) (DEFAULT_RATE * speed));
		first = false;
		at.play();
	} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related AudioTrack flush Questions & Answers:

flush Method Overview
Flushes the audio data currently queued for playback.
See Code Examples for other Android AudioTrack Methods: