title: Playing multiple byte arrays simultaneously in Java
body: <p>How can you play multiple (audio) byte arrays simultaneously? This "byte array" is recorded by TargetDataLine, transferred using a server.</p>
  
  <p><strong>What I've tried so far</strong></p>
  
  <p><em>Using SourceDataLine:</em></p>
  
  <p>There is no way to play mulitple streams using SourceDataLine, because the write method blocks until the buffer is written. This problem cannot be fixed using Threads, because only one SourceDataLine can write concurrently.</p>
  
  <p><em>Using the AudioPlayer Class:</em></p>
  
  <pre><code>ByteInputStream stream2 = new ByteInputStream(data, 0, data.length);
  AudioInputStream stream = new AudioInputStream(stream2, VoiceChat.format, data.length);
  AudioPlayer.player.start(stream);
  </code></pre>
  
  <p>This just plays noise on the clients.</p>
  
  <p>EDIT
  I don't receive the voice packets at the same time, it's not simultaneously, more "overlapping".</p>