Android的MediaRecorder setOutPutFile()采用Socket流 [英] Android MediaRecorder setOutPutFile() to stream using Socket

查看:3658
本文介绍了Android的MediaRecorder setOutPutFile()采用Socket流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序,应能流视频到我的网络上的本地服务器,而无需在SD卡上存储它。

I am developing an Android app that should be capable of streaming video to a local server on my network without storing it on SD card.

为此,我已在C#中简单的socket应用程序,侦听特定的IP:端口

For this I have made simple socket application in C# that listens to the specific IP:PORT

在Android的一部分,我已经设置了 setOutputFile()到这个IP:端口使用插座

On Android part, I had set the setOutputFile() to this IP:PORT using socket.

该应用完全可以在Android手机上启动,但它不会显示preVIEW,当我开始录制退出没有任何异常。它也不发送任何数据流到网络。

This application starts perfectly on Android phone but it does not display preview and when I start recording it exits without any exception. It also do not send any data stream to the network.

当我设置了 setOutPutFile()到SD卡,它完美的作品,并录制视频。

When I set the setOutPutFile() to SD card, it works perfectly and records video also.

对于服务器的一部分,当我从其他应用程序(从PC)将数据发送到同一个IP:端口,接收到的数据。

For the server part, when I send the data from any other app (from PC) to the same IP:PORT, it receives the data.

总之,我想用插座,流建立PC和Android之间的沟通渠道。

In short, I want to establish the communication channel between PC and Android using socket for streaming.

这是我的Andr​​oid code:

 Socket soc=new Socket("192.168.1.3",8210);
 ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(soc);
 ...
 ...
 // other Recorder setup steps
 ...
 ...
 Recorder.setOutputFile(pfd.getFileDescriptor()); // working fine for sdcard
 Recorder.setPreviewDisplay(holder.getSurface());
 Recorder.prepare();

这是我的服务器上的应用程序,在C#中,运行于PC:

 socketForServer = new TcpClient("192.168.1.3", 8210);
 NetworkStream networkStream = socketForServer.GetStream();
 byte[] rData = new byte[1024];
 networkStream.Read(rData, 0, 1024);
 ...
 ...
 // process rData
 ...
 ...

我无法理解,在这里发生的问题。我是不是在正确的方向?

I am not able to understand the problem that is occurring here. Am I going in right direction?

推荐答案

有问题,我的服务器code。

There was problem in my server code.

我不得不使用的TcpListener 的TcpClient

下面是正确的code:

Following is the correct code:

TcpListener listener = new TcpListener(ipAddress, 8210);
Socket s = listener.AcceptSocket();
NetworkStream ns = new NetworkStream(s);
.
.
.
//reading the data from stream
.
.
.

这篇关于Android的MediaRecorder setOutPutFile()采用Socket流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆