I'm working on the Android application which is using JLayer library to decode MP3 file (I need access to audio samples) and AudioTrack object to play it. I have something like this:
int timeMarker = 0;
int timeStep = 5000;
while (!isCancelled()) {
outSignalBuffer = decode(fileToPlay.getPath(), timeMarker, timeStep, bufferSize);
audioTrack.write(outSignalBuffer, 0, outSignalBuffer.length);
//publishProgress(outSignalBuffer);
timeMarker += timeStep;
}
This code is placed in my custom player created as AsyncTask. In general my decode and write method works OK because I hear sound file. The problem is, that my sound regularly jerk in every 5 seconds (timeStep = 5000 ms). As I see audioTrack.write(...) blocks my async task, so the short pause after every time Steps is caused by waiting to result from decode method.
Do you have any advices what is the best approach to correctly deliver outSignalBuffer to write method from decoder to get smooth audioTrack player?