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 javax.sound.sampled.AudioFormat;
- import javax.sound.sampled.TargetDataLine;
- public class ClientAudio implements Runnable {
- private String ip;
- private Socket s2;
- private ObjectOutputStream o2;
- private TargetDataLine microphone;
- private AudioFormat audioformat;
- public ClientAudio(String ipAddress, TargetDataLine mic, AudioFormat af) {
- ip = ipAddress;
- microphone = mic;
- audioformat = af;
- }
- public void run() {
- try {
- s2 = new Socket(ip, 1210);
- o2 = new ObjectOutputStream(s2.getOutputStream());
- Thread car = new Thread(new ClientAudioRec(s2, audioformat));
- car.start();
- System.out.println("AUDIO");
- int bytesRead = 0;
- byte[] soundData = new byte[1];
- while(true) {
- bytesRead = microphone.read(soundData, 0, bytesRead);
- if(bytesRead >= 0) {
- o2.write(soundData, 0, bytesRead);
- o2.flush();
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment