Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package client;
- import java.io.IOException;
- import java.io.ObjectOutputStream;
- import java.net.Socket;
- import java.util.ArrayList;
- import javax.sound.sampled.*;
- public class VoiceUser extends Thread {
- private ObjectOutputStream clientOutput;
- private ArrayList<ObjectOutputStream> vOutputArray = new ArrayList<ObjectOutputStream>();
- private TargetDataLine microphone;
- public VoiceUser(Socket sv, TargetDataLine mic) {
- try {
- microphone = mic;
- clientOutput = new ObjectOutputStream(sv.getOutputStream());
- vOutputArray.add(clientOutput);
- } catch (IOException e) {
- System.out.println("Can't create stable connection between server and client");
- }
- }
- public void run() {
- try {
- int bytesRead = 0;
- byte[] soundData = new byte[1];
- while(bytesRead != -1)
- {
- bytesRead = microphone.read(soundData, 0, soundData.length);
- if(bytesRead >= 0)
- {
- for(ObjectOutputStream o : vOutputArray) {
- o.write(soundData, 0, bytesRead);
- }
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement