MediaRecorder IOException: prepare failed

后端 未结 6 415
北恋
北恋 2021-01-18 08:11

I want to use MediaRecorder to record voice, my code is:

 public void record(View v) {
       Log.d(TAG, \"record\");

    this.mediaRecorder.setAudioChannel         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-18 08:44

    This is a big problem but has a very small solution

    In most cases, the filename that we get from this.file.getAbsolutePath() contains file:/// as a prefix

        ////////////////////////////////////////////////* INCORRECT CODE */
        this.mediaRecorder.setOutputFile(this.file.getAbsolutePath());
        /*the above line sets a file url beginning with a "file:///"
        //however, since this setOutputFile requires us to send a
        //string referring to the uri, we will have to get rid of the
        //"file:///" and simply write the uri */
        ////////////////////////////////////////////////* CORRECTED CODE BELOW */
        this.mediaRecorder.setOutputFile(this.file.getAbsolutePath().substring(8));
        /*the above line of code extracts the string uri eliminating
        // file:/// */
    

    Hope you find this answer helpful

提交回复
热议问题