Android MediaRecorder OutputFile: Title does not update when using FileDescriptor

I just want to capture audio on my Android and transfer it through a socket to another server. Everything works as it should, except that the file cannot be read at the other end.

After some testing and file matching, it seems that when recording audio data to a file, MediaRecorder will update the header at some point, possibly when the recording is complete. I do not know if this is a codec or a format that indicates this. The problem becomes apparent when using FileDescriptor to write to a socket. Obviously, header updates cannot happen after data has been written to the socket.

I read many other posts about streaming audio / video over a socket and have not met anyone who talked about this issue. Maybe I need to change the format or codec to something that does not require returning and updating the header?

    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
+4
source share

All Articles