Android AudioTrack - top ranked examples from Open Source projects

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

This code example shows how to use the following methods: release, stop
thread = null;
		 
 
		if(oTrack!=null){
			oTrack.stop();
			oTrack.release();
			oTrack = null;
		} 
		if(iTrack!=null){
			iTrack.release();
			iTrack = null;
		} 
		 
	} 
 
	@Override 
	protected void appPause() { 
		if(broadcastReceiver != null){
			try{ 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: play
            mAudio = new AudioTrack(AudioManager.STREAM_MUSIC,
                    rate,
                    channels,
                    encoding,
                    bufSize,
                    AudioTrack.MODE_STREAM );
            mAudio.play();
        } 
        return mVirtualBufSize;
    } 
 
    public byte[] getBuffer() 
    { 
        return mAudioBuffer;
    } 
 
    public int deinitAudio() 
    { 
        if( mAudio != null )
        { 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getAudioFormat, getChannelCount, getSampleRate, getState
				AudioFormat.CHANNEL_CONFIGURATION_STEREO :
				AudioFormat.CHANNEL_CONFIGURATION_MONO);
 
		// avoid recreation if no parameters change 
		if (track != null &&
				track.getSampleRate() == rate &&
				track.getAudioFormat() == format &&
				track.getChannelCount() == channels)
			return true; 
 
		int bufferSize = AudioTrack.getMinBufferSize(
				rate, channelConfig, format) * 2;
		if (bufferSize < 1500)
			bufferSize = 1500;
 
		try { 
			track = new AudioTrack(
					AudioManager.STREAM_MUSIC,
					rate,
					channelConfig,
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getPlayState, play, write
    } 
 
    @CalledByNative 
    private void playOutputBuffer(byte[] buf) {
        if (mAudioTrack != null) {
            if (AudioTrack.PLAYSTATE_PLAYING != mAudioTrack.getPlayState()) {
                mAudioTrack.play();
            } 
            int size = mAudioTrack.write(buf, 0, buf.length);
            if (buf.length != size) {
                Log.i(TAG, "Failed to send all data to audio output, expected size: " +
                        buf.length + ", actual size: " + size);
            } 
        } 
    } 
 
    @CalledByNative 
    private void setVolume(double volume) {
        if (mAudioTrack != null) {
            mAudioTrack.setStereoVolume((float) volume, (float) volume);
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: play, setStereoVolume
		int minBufferSize = AudioTrack.getMinBufferSize(sampleRate, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT);
		 
		if (minBufferSize < bufferSize * 4)
			minBufferSize = bufferSize * 4;
		 
		audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT, minBufferSize, AudioTrack.MODE_STREAM);
		 
		float audioVolume = AudioTrack.getMaxVolume();
		audioTrack.setStereoVolume(audioVolume, audioVolume);
		 
		audioTrack.play();
	} 
	 
	public void updateSound() 
	{ 
		audioTrack.write(audioBuffer, 0, bufferSize);
	} 
 
	public void setPhysicalScreenResolution(int width, int height)
	{ 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android AudioTrack Questions & Answers:

See Code Examples for Android AudioTrack Methods: