我编写了一个应用程序,它通过TCP将音频从客户端传输到服务器,但它不起作用,即没有声音输出。你能检查我的代码告诉我它有什么问题吗?
客户端:
foreach (var file in unAllowed)
file.MoveTo(Path.Combine(Directory.GetCurrentDirectory(), file.Name));
服务器
public void startStreaming(){ 线程streamThread = new Thread(new Runnable(){
public void startStreaming() {
Thread streamThread = new Thread(new Runnable() {
@Override
public void run() {
try {
int minBufSize =AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
Log.d("VD ", "Bufer intioalised "+minBufSize);
short[] buffer=new short[minBufSize];
Log.d("VS","Buffer created of size .c" + minBufSize);
// DatagramPacket packet;
final InetAddress destination = InetAddress.getByName(target.getText().toString());
port=Integer.parseInt(target_port.getText().toString());
Socket socket=new Socket(destination,port);
DataOutputStream dos=new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
Log.d("VS", "Address retrieved.c");
if (minBufSize != AudioRecord.ERROR_BAD_VALUE) {
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,sampleRate,channelConfig,audioFormat,minBufSize);
Log.d("VS", "Recorder initialized.c");}
if (recorder.getState() == AudioRecord.STATE_INITIALIZED){
Log.d("VS", "Recorder working....c");
recorder.startRecording();}
BufferedWriter input;
while(status == true) {
//reading data from MIC into buffer
int bufferReadResult = recorder.read(buffer, 0, buffer.length);
dos.write(buffer,0,bufferReadResult);
dos.flush();
}
} catch(UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
Log.e("IOException message:",e.getMessage().toString());
}
}
请给我最好的帮助。
答案 0 :(得分:1)
答案在评论中。服务器和客户端read()/ write()都必须更好地实现。