I'm trying to stream music in using AudioTrack. The track plays, but the audio plays at half the rate. It's like the song has become slow motion.
try{
AudioTrack track= new AudioTrack( AudioManager.STREAM_MUSIC,
44100,
android.media.AudioFormat.CHANNEL_CONFIGURATION_MONO,
android.media.AudioFormat.ENCODING_PCM_16BIT,
android.media.AudioTrack.getMinBufferSize( 44100,
android.media.AudioFormat.CHANNEL_CONFIGURATION_STEREO,
android.media.AudioFormat.ENCODING_PCM_16BIT ),
AudioTrack.MODE_STREAM );
System.out.println("Min buffer: " + android.media.AudioTrack.getMinBufferSize( 44100,
android.media.AudioFormat.CHANNEL_CONFIGURATION_STEREO,
android.media.AudioFormat.ENCODING_PCM_16BIT ));
int cnt;
int totalWrite = 0;
boolean play = true;
byte buff[]=new byte[16384];
while((cnt=CircularByteBuffer.getInstance().getInputStream().read(buff))>0){
totalWrite += cnt;
System.out.println("Writing: " + cnt);
track.write(buff, 0, cnt);
if ( totalWrite > 60000 && play ){
track.play();
play = false;
}
}
}catch (Exception e)
{
}//end catch
In the CircularByteBuffer, the bytes are being written on another thread and read on this one. The song plays consistently without any pauses, but it just plays at a slow rate. I have no idea what it could be. Any ideas?