title: How to play sounds in Java games?
body: <p>I'm successfully playing sounds in a Java (1.5) applet game using the following code:</p>
  
  <pre><code>// get an available clip to play it
  Clip clip = null;
  for (Clip clipTemp : players) {
      if (!clipTemp.isOpen()) {
      clip = clipTemp;
          break;
      }
  }
  if (clip == null) {
      // no available player found, don't play
      return;
  }
  
  clip.open(audioFormat, audioByteData, 0, audioByteData.length);
  
  clip.start();
  </code></pre>
  
  <p>(Players are a list of clips that I open at the start with the aim to reduce latency, a line listener closes the line when the stop event is retrieved.)</p>
  
  <p>The problem I'm facing is intermittent delays of upto 1 second when playing a sound. This is pretty poor.</p>
  
  <p>Is there any way to improve this? Are <code>SourceDataLines</code> worth considering?</p>