录音在某些设备上不起作用

时间:2018-08-28 09:12:28

标签: android audio-recording illegalstateexception background-service audiorecord

我正在使用android audiorecoder录制音频,但是它无法在某些设备中使用,例如Huawei和oppo,我在后台服务中录制了5秒钟的音频。 开始录音的功能是:

Caused by: java.lang.ClassNotFoundException: jdk.internal.reflect.MethodAccessorImpl from [Module "org.jboss.ws.common:main" from local module loader @2cbb3d47

停止录音功能是

private void startRecording(File file) {
    if (mediaRecorder != null) {
        mediaRecorder.reset();
        mediaRecorder.release();
    }
    mediaRecorder = new MediaRecorder();
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
   // mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
    //mediaRecorder.setOutputFile(file.getAbsolutePath());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.HE_AAC);
        mediaRecorder.setAudioEncodingBitRate(48000);
    } else {
        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        mediaRecorder.setAudioEncodingBitRate(64000);
    }
    mediaRecorder.setAudioSamplingRate(16000);
    mediaRecorder.setOutputFile(file.getAbsolutePath());

    try {
        mediaRecorder.prepare();
        mediaRecorder.start();
    } catch (IOException e) {
        Log.e("giftlist", "io problems while preparing [" +
                file.getAbsolutePath() + "]: " + e.getMessage());
    }
}

这是期望

private void stopRecording() {
    if (mediaRecorder != null) {
        mediaRecorder.stop();
        mediaRecorder.reset();
        mediaRecorder.release();
        mediaRecorder = null;
    }
}

它给出了非法堆栈异常。如何解决这个问题?我想在所有设备上运行它

0 个答案:

没有答案