How to record video on Android into Stream

我与影子孤独终老i 提交于 2019-11-30 02:10:17

You can do it using ParcelFileDescriptor.fromSocket():

String hostname = "example.com";
int port = 1234;

Socket socket = new Socket(InetAddress.getByName(hostname), port);

ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);

MediaRecorder recorder = new MediaRecorder();
recorder.setOutputFile(pfd.getFileDescriptor());
recorder.prepare();
recorder.start();

If you prefer UDP, use ParcelFileDescriptor.fromDatagramSocket() instead.

Credit where credit is due.

4ntoine

Using Android-specific LocalServerSocket seems to be the only possible way to get video data as stream. In brief, you have to:

  1. create LocalServerSocket instance
  2. set it as output file to MediaRecorder instance using file descriptor (mediaRecorder.setOutputFile(FileDescriptor fd);)
  3. accept connection
  4. read bytes from it (as from InputStream) in separate thread in loop

Another ideas?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!