I want android.media.MediaRecorder. to record audio not into file, but into same variable, for example char[ ] or byte[ ] or some other datta buffer structure. I want to send it to the remote server via Wi-Fi, can android.media.MediaRecorder provide this functionality?
What you can do here is utilize the ParcelFileDescriptor class.
//make a pipe containing a read and a write parcelfd ParcelFileDescriptor fdPair = ParcelFileDescriptor.createPipe(); //get a handle to your read and write fd objects. ParcelFileDescriptor readFD = fdPair; ParcelFileDescriptor writeFD = fdPair; //next set your mediaRecorder instance to output to the write side of this pipe. mediaRecorder.setOutputFile(writeFD.getFileDescriptor()); //next create an input stream to read from the read side of the pipe. FileInputStream reader = new FileInputStream(readFD.getFileDescriptor()); //now to fill up a buffer with data, we just do a simple read byte buffer = new byte;//or w/e buffer size you want //fill up your buffer with data from the stream reader.read(buffer);// may want to do this in a separate thread
and now you have a buffer full of audio data
alternatively, you may want to write data directly to a socket from the recorder. this can also be achieved with the ParcelFileDescriptor class.
//create a socket connection to another device Socket socket = new Socket("184.108.40.206",65535);//or w/e socket address you are using //wrap the socket with a parcel so you can get at its underlying File descriptor ParcelFileDescriptor socketWrapper = ParcelFileDescriptor.fromSocket(socket); //set your mediaRecorder instance to write to this file descriptor mediaRecorder.setOutputFile(socketWrapper.getFileDescriptor());
now any time your media recorder has data to write it will automatically write it over the socket