android-所有设备都支持哪种MediaRecorder配置?

android-所有设备都支持哪种MediaRecorder配置?,android,mediarecorder,Android,Mediarecorder,我正在我的应用程序中录制通信语音,我添加了存储和音频录制权限清单,并以编程方式获取 我的代码在一台设备上运行良好(Android 6.0 Lenovo K3 Note) 但不在另一台上(安卓8.1 ONEPLUS A5010) 在第二种情况下,设备输出保存为3.15KB的空白文件 我正在添加我正在使用的代码,请告诉我做错了什么 MediaRecorder mRecorder; String mFileName; OnCreate中的代码 File file = new File(getF

我正在我的应用程序中录制通信语音,我添加了存储和音频录制权限清单,并以编程方式获取

我的代码在一台设备上运行良好(Android 6.0 Lenovo K3 Note) 但不在另一台上(安卓8.1 ONEPLUS A5010)

在第二种情况下,设备输出保存为3.15KB的空白文件

我正在添加我正在使用的代码,请告诉我做错了什么

 MediaRecorder mRecorder;
 String mFileName;
OnCreate中的代码

 File file = new File(getFilesDir(), "engwingoLastCall.3gp");

                 mFileName = file.getAbsolutePath();

try {
        if(mRecorder == null) {
            mRecorder = new MediaRecorder();
            mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            mRecorder.setOutputFile(mFileName);
            mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        }
    } catch (Exception e) {
        Log.d(TAG,"Recorder Error:"+e.getMessage());
    }
方法

public void startRecording() {

    try {
        if(mRecorder != null) {
            mRecorder.prepare();
            mRecorder.start();
        }
    } catch (Exception e) {
        Log.d("Recorder", "prepare() failed");

    }


}
public void stopRecording() {

    if(mRecorder != null) {

        try {
            mRecorder.stop();
            mRecorder.release();
            mRecorder = null;
        } catch (IllegalStateException e) {
            e.printStackTrace();
        }catch (Exception e){
            Log.d(TAG,e.getMessage());

        }
    }
}

由于您没有使用
setProfile()
方法设置配置文件,因此可能还需要设置音频通道、比特率和采样率。以下是一个例子:

mRecorder.setAudioChannels(1);
// you would not want to record stereo, it is not logical

mRecorder.setAudioEncodingBitRate(128000);
// you can set it to 64000 or 96000 to lower quality, therefore decreasing the size of the audio

mRecorder.setAudioSamplingRate(44100);
// AFAIK, default value.

希望这有帮助。

我的代码还可以,但我的录音机出现这种行为的原因是,
当时还有其他一些服务也在使用我的录音机,这就是为什么文件保存为空(3.15KB大小)

因为您没有设置配置文件,可能需要调用setAudioEncodingBitRate,setAudioSamplingRate和SetAudioChannel方法。您能提供示例,以便我可以测试解决我问题的方法吗…谢谢…您可以发布答案,以便我可以接受。