Advertisement
Guest User

Server Side Voice

a guest
Apr 29th, 2016
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. package client;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectOutputStream;
  5. import java.net.Socket;
  6. import java.util.ArrayList;
  7.  
  8. import javax.sound.sampled.*;
  9.  
  10. public class VoiceUser extends Thread {
  11.     private ObjectOutputStream clientOutput;
  12.     private ArrayList<ObjectOutputStream> vOutputArray = new ArrayList<ObjectOutputStream>();
  13.     private TargetDataLine microphone;
  14.    
  15.     public VoiceUser(Socket sv, TargetDataLine mic) {
  16.         try {
  17.             microphone = mic;
  18.             clientOutput = new ObjectOutputStream(sv.getOutputStream());
  19.             vOutputArray.add(clientOutput);
  20.         } catch (IOException e) {
  21.             System.out.println("Can't create stable connection between server and client");
  22.         }
  23.     }
  24.     public void run() {
  25.         try {
  26.             int bytesRead = 0;
  27.             byte[] soundData = new byte[1];
  28.             while(bytesRead != -1)
  29.             {
  30.                 bytesRead = microphone.read(soundData, 0, soundData.length);
  31.                 if(bytesRead >= 0)
  32.                 {
  33.                     for(ObjectOutputStream o : vOutputArray) {
  34.                             o.write(soundData, 0, bytesRead);
  35.                     }
  36.                 }
  37.             }
  38.         } catch (IOException e) {
  39.             e.printStackTrace();
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement