9

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.

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

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

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.

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

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

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

Here is my Android 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();

Here is my server app that is in C# and runs on 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?

4
  • Hello Vinod, could you release the source code of the android app? I try to do the same thing, but the video freeze, and I don't know why... Thanks.
    – Rob
    May 3, 2011 at 6:12
  • Hi, Sorry I can't release the code as it is from a commercial project. If you could send me your code, I will try to fix the issue. Thanks May 3, 2011 at 7:33
  • I basically do the same thing than you, but I'm struggling on the format... I receive something, but without the good header I think. My problem is really well described here (mattakis.com/blog/kisg/20090708/…) but I dont know how to deal with. Could you just show that small part? Thanks.
    – Rob
    May 5, 2011 at 7:37
  • Hi Vinod, I am also facing a problem in recording. My server side is working fine but from my android client I am not able to send the data. So, if possible can you please provide some of sample source code.
    – Murtz
    May 21, 2013 at 7:52

1 Answer 1

5

There was problem in my server code.

I had to use TcpListener in place of TcpClient.

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
.
.
.
3
  • 1
    Hi Vinod, I am trying to do the same but the .NET server side is not working fine in my case, any chance to get your working code?
    – Giuseppe
    Apr 12, 2013 at 5:58
  • @Giuseppe the code is now an IP so I can't share the code but if you could elaborate your problem then I can help. Apr 12, 2013 at 6:20
  • 1
    So, you're able to stream from the Android MediaPlayer with the PFD -> FD by way of Socket? Aug 23, 2014 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.