Android MediaRecorder in streaming

前端 未结 2 795
不知归路
不知归路 2021-01-02 14:36

Its possible to \"stream\" result of MediaRecorder?

The unique method i can see is mediaRecorder.setOutputFile that receives a FileDescriptor. So i can write the res

2条回答
  •  情书的邮戳
    2021-01-02 15:24

    Yes it is possible. Here is the sample code with FileDescriptor and socket:

        socket = new Socket("192.168.1.234",8888);
        ParcelFileDescriptor fileDescriptor = ParcelFileDescriptor.fromSocket(socket);
    
        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mRecorder.setOutputFile(fileDescriptor.getFileDescriptor);
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    
        try {
            mRecorder.prepare();
        } catch (IOException e) {
            Log.e(LOG_TAG, "prepare() failed");
        }
    
        mRecorder.start();
    

提交回复
热议问题