Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaRecorder and UDP (DatagramSocket) in Android

I am currently writing a program that is a sort of VoIP client. I am trying to establish a connection between 2 clients and send and receive data, that is recorded from microphone.

I am currently using files but it looks like an awful implementation:

The recorder starts recording to a temporary file. A timer kicks in, stop the recorder, look at the file size, to then send the content using a DatagramPacket.

It seems awfully bad. I wonder if the MediaRecorder and MediaPlayer class have a way to take a UPD socket as it's file output and input respectively (that is, a DatagramSocket).

I can use a file descriptor from a socket, but sockets uses TCP. I wanted to use UDP, so I guess DatagramSocket, but I can't seem to find a way to use it in my MediaRecorder and MediaPlayer class.

Does anyone please have a good solution for this?

Thank you very much

like image 730
Jary Avatar asked Nov 05 '22 06:11

Jary


1 Answers

You are probably interested in a ParcelFileDescriptor, and then specifically the fromDatagramSocket(...) function, then you could use the getFileDescriptor function to set the Datasource of the player

*update: this only works offcourse if you have android 4.0 or higher: see the api limit

like image 151
Ronnie Avatar answered Nov 15 '22 08:11

Ronnie