【发布时间】:2012-01-24 11:23:06
【问题描述】:
我想了解套接字是如何工作的,特别是我需要一些代码示例供服务器端接收 mediarecorder 从设备发送的流。
非常感谢您的帮助。
我真正的最终意图是在设备上讲话并在 PC 上收听,只是一个方向。
目前我可以使用以下代码发送流:
String hostname = "192.168.1.10";
int port = 8000;
Socket socket = null;
try {
socket = new Socket(InetAddress.getByName(hostname), port);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(pfd.getFileDescriptor());
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
recorder.start();
【问题讨论】:
-
您在 PC 上使用什么语言?
-
我用的是.NET平台,vb.net或者c#都一样。
标签: android sockets multimedia