Hello All,
I want to play buffer audio from pcm or wav format files programmatically. I use AudioTrack API for that. But the problem which i'm observing is, it plays properly for lowest audio bitrate files, for ex: if i have a .wav file which has 88,000 audio bit rate, it pays well, otherwise if i have any other files more than this bitrate (or) bigger Size wav file, it is giving some junk sound instead of the proper audio sound. What is the problem here? AudioTrack should be able to play only lower bitrate files? (or) Do i need to modify anything in the code? Could someone suggest me?
- Code: Select all
private void PlayMyAudio(String filePath) throws IOException
{
byte[] byteData;
File file = new File(filePath); // it is a .wav file
byteData = new byte[(int) file.length()];
FileInputStream in = null;
try {
in = new FileInputStream( file );
in.read( byteData );
in.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int intSize = android.media.AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);
AudioTrack at = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, intSize, AudioTrack.MODE_STREAM);
at.play();
// Write the byte array to the track
at.write(byteData, 0, byteData.length);
at.stop();
}


