Code example for AudioTrack

Methods: playwrite

0
	private void playSound(byte[] sound){
		final byte[] play = sound;
		(new Thread(new Runnable() {
			@Override 
			public void run() { 
				AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, numSamples, AudioTrack.MODE_STATIC);
				audioTrack.write(play, 0, numSamples);
				audioTrack.play();
			}})).start();
	} 
 
	@Override 
	public void onClick(View arg0) {
		if (arg0 == buttonDo1) playSound(sSampleDo1);
		if (arg0 == buttonRe) playSound(sSampleRe);
		if (arg0 == buttonMi) playSound(sSampleMi);
		if (arg0 == buttonFa) playSound(sSampleFa);
		if (arg0 == buttonSo) playSound(sSampleSo);
		if (arg0 == buttonLa) playSound(sSampleLa);
		if (arg0 == buttonTi) playSound(sSampleTi);
		if (arg0 == buttonDo2) playSound(sSampleDo2);