Android Streaming Using ParcelFileDescriptor and MediaRecorder

For streaming video over socket in Android, the following approach is taken

String hostname = "your.host.name";
int port = 1234;
Socket socket = new Socket(InetAddress.getByName(hostname), port);
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
MediaRecorder recorder = new MediaRecorder();
// Additional MediaRecorder setup (output format ... etc.) omitted
recorder.setOutputFile(pfd.getFileDescriptor());
recorder.prepare();
recorder.start();

      

I have created a TCP server and I can receive messages on the TCP server using the socket object (code above) Output Stream. Also I can save the video by specifying the path, eg. "/sdcard/video.mp4" in setOutFile (). With the above code, I am getting nothing on the TCP server and also seeing MediaRecorder: start failed: -38 in the logs. Also I tried to close all running applications by going to Settings-> Applications-> Launch.

+3


source to share





All Articles