Search code examples
javamultithreadingdelaywav

Latency when pausing/stopping WaveAudioStream


I have just found the code to a small WAV player.

It works well but when clicking the "Pause" and "Stop" buttons there's like a 2 seconds delay which makes the app look really unprofessional. I have no idea what is causing this but I'd really like to have it fixed, could anyone inspect the code and tell me where it comes from? Thanks!


Solution

  • I wrote this sample for a time and don't remember very well.

    In my opinion the latency comes mainly from the update frame functions. In the class VisualPlayer, UI are update by a timer which pick up the current values from the thread. It's not very efficient but faster for write this sample. The best way to update UI is implementing a Runnable class and call it with SwingUtilities.invokeLater().

    Also have you try to reduce read buffer size ?