public static void main(String[] args) throws Exception{
final AudioInputStream a1= AudioSystem.getAudioInputStream(new File("d:\\bunny_troubles.wav"));
DataLine.Info lineInfo1 = new DataLine.Info( SourceDataLine.class, a1.getFormat());
final AudioInputStream a2 = AudioSystem.getAudioInputStream(new File("d:\\borg.wav"));
DataLine.Info lineInfo2 = new DataLine.Info( SourceDataLine.class, a2.getFormat());
Mixer.Info[] mis = AudioSystem.getMixerInfo();
for(int i = 0; i < mis.length; i++){
Mixer.Info mi = mis[i];
if(mi.getName().equals("Java Sound Audio Engine")){
Mixer m = AudioSystem.getMixer(mi);
final SourceDataLine sourceDataLine1 = (SourceDataLine )m.getLine(lineInfo1);
final SourceDataLine sourceDataLine2 = (SourceDataLine )m.getLine(lineInfo2);
Thread t1 = new Thread(){
public void run(){
byte[] buf = new byte[1024];
try {
int l;
while((l = a1.read(buf))!= -1){
sourceDataLine1.write(buf, 0, l);
}
while(sourceDataLine1.isActive()){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
sourceDataLine1.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
t1.setDaemon(true);
Thread t2 = new Thread(){
public void run(){
byte[] buf = new byte[1024];
try {
int l;
while((l = a2.read(buf))!= -1){
sourceDataLine2.write(buf, 0, l);
}
while(sourceDataLine2.isActive()){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
sourceDataLine2.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
t2.setDaemon(true);
sourceDataLine1.open();
sourceDataLine1.start();
t1.start();
sourceDataLine2.open();
sourceDataLine2.start();
t2.start();
t1.join();
t2.join();
break;
}
}
}