java 语音聊天核心代码(2)
int numBytesRead = 0;
line.start();
while (thread != null) {
try{
numBytesRead = playbackInputStream.read(data);
line.write(data, 0,numBytesRead);
} catch (IOException e) {
break;
}
}
if (thread != null) {
line.drain();
}
line.stop();
line.close();
line = null;
}
}
//音频捕获部分,
import java.io.*;
import javax.sound.sampled.*;
import java.net.*;
/**
* Title: VoiceChat
* Description: 音频捕捉(录音程序)
* Copyright: Copyright (c) 2001
*/
class Capture implements Runnable {
TargetDataLine line;
Thread thread;
Socket s;
BufferedOutputStream captrueOutputStream;
Capture(Socket s){//构造器 取得socket以获得网络输出流
this.s=s;
}
public void start() {
thread = new Thread(this);
thread.setName("Capture");
thread.start();
}
public void stop() {
thread = null;
}
public void run() {
相关新闻>>
- 发表评论
-
- 最新评论 更多>>