Hello,
i'm working on a mod for minecraft called Voice Chat. I'm pretty much finished but there is one error .
The problem is that the write method of sourcedataline "waits" until the full buffer is played. This is a huge problem and causes delays after some time. So i made a play thread for every player. Every thread uses his own sourcedataline.
But doesn't help at all because this buffer can only be written until every other sourcedataline finished writing.
Here is my code.
public SourceDataLine source; public ArrayList<AudioData> data; public String username; public int lastpacket = 0; public PlayThread(String username) { this.username = username; data = new ArrayList<AudioData>(); System.out.println("Start Playing sound"); DataLine.Info info2 = new DataLine.Info(SourceDataLine.class, VoiceChat.format); try { source = (SourceDataLine) AudioSystem.getLine(info2); source.open(VoiceChat.format); source.start(); } catch (LineUnavailableException ex) { } } public void addPacket(byte[] data, int length) { this.data.add(new AudioData(data, length)); } @Override public void run() { while(mc.theWorld != null && !mc.isSingleplayer() && lastpacket < 10000) { if(data.size() > 0) { while(data.size() > 0) { AudioData audio = data.get(0); source.write(audio.data, 0, audio.length); data.remove(0); if(data.size() > 20) { System.out.println("Remove all queued packets (" + data.size() + ") to make the delay smaller"); data.clear(); } } source.drain(); lastpacket = 0; } lastpacket++; try { sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println("Stop playing sound"); threads.remove(this); }
Is there a why of multiple playing sound? I have no idea how to solve this problem. I would be very happy if someone could help me .
I'm not really sure if this is the right topic, but the title contains streams