Mekanism-tilera-Edition/common/mekanism/client/voice/VoiceOutput.java

58 lines
1.3 KiB
Java
Raw Normal View History

2013-10-14 20:08:15 +02:00
package mekanism.client.voice;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
2013-10-14 20:08:15 +02:00
public class VoiceOutput extends Thread
{
public VoiceClient voiceClient;
public DataLine.Info speaker;
2013-10-14 20:08:15 +02:00
public SourceDataLine sourceLine;
public VoiceOutput(VoiceClient client)
{
voiceClient = client;
speaker = new DataLine.Info(SourceDataLine.class, voiceClient.format, 2200);
2013-10-14 20:08:15 +02:00
setDaemon(true);
setName("VoiceServer Client Output Thread");
}
@Override
public void run()
{
try {
sourceLine = ((SourceDataLine)AudioSystem.getLine(speaker));
sourceLine.open(voiceClient.format, 2200);
sourceLine.start();
while(voiceClient.running)
{
2013-10-19 02:05:47 +02:00
try {
short byteCount = voiceClient.input.readShort();
byte[] audioData = new byte[byteCount];
voiceClient.input.readFully(audioData);
sourceLine.write(audioData, 0, audioData.length);
} catch(Exception e) {}
2013-10-14 20:08:15 +02:00
}
} catch(Exception e) {
System.err.println("[Mekanism] VoiceServer: Error while running client output thread.");
2013-10-14 20:08:15 +02:00
e.printStackTrace();
}
}
public void close()
{
sourceLine.flush();
sourceLine.close();
}
}