...
bufferSize = AudioTrack.getMinBufferSize(sampleRateInHz,
AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
if (bufferSize != AudioTrack.ERROR_BAD_VALUE && bufferSize != AudioTrack.ERROR) {
audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
this.sampleRateInHz, AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT, this.bufferSize,
AudioTrack.MODE_STREAM);
if(audioTrack!=null && audioTrack.getState() == AudioTrack.STATE_INITIALIZED){
Log.i(LOG_TAG,"Audio Track instance created buffer Size : "+this.bufferSize);
audioTrack.setPositionNotificationPeriod(320);
audioTrack.setPlaybackPositionUpdateListener(this);
audioTrack.play();
short[] tempBuf =new short[bufferSize/2];
// now write the code here to fill the tempBuf by reading from the file in shorts or bytes
audioTrack.write(tempBuf,0, tempBuf.length);
}else{
Log.e(LOG_TAG,"Unble to create AudioTrack instance");
}
} else {
Log.e(LOG_TAG, "Unable to get the minimum buffer size");
}