6

I'm using an AudioTrack instance to play music. When the user changes songs or seeks within the song I want to flush the buffer before playing the new data. The documentation for stop() seems to guide me towards doing something like:

audioTrack.pause();
audioTrack.flush();
audioTrack.play(); 
audioTrack.write(newData, ...);

However, this often produces a slight static. I've tried a few workarounds. One that works (as in getting rid of the static) on my test device is Thread.sleep(10, 0) after the flush(). But it feels very hackish and arbitrary, what if it doesn't work on some other device? Also I'd like to not block a nanosec longer than necessary.

What is the proper way to address this?

PEZ
  • 16,821
  • 7
  • 45
  • 66

0 Answers0