Android - HTC手机中的录音

时间:2013-11-18 15:12:53

标签: java android

当我使用三星或任何其他Android手机时,我没有问题,但是当我想使用我的HTC One X +时,录音机崩溃并且无法启动。

这是logcat输出:

    ⁃   11-18 18:37:39.963: E/MediaRecorder(27698): start failed: -2147483648
⁃   11-18 18:37:39.963: E/MediaRecorder(27698): start failed.
⁃   11-18 18:37:39.963: E/MediaRecorder(27698): try to delete broken file: /storage/emulated/0/callrec/+989203626397_10|18|-18:37.AAC
⁃   11-18 18:37:39.968: W/dalvikvm(27698): threadid=1: thread exiting with uncaught exception (group=0x41f86a08)
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698): FATAL EXCEPTION: main
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698): java.lang.RuntimeException: start failed.
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698):    at android.media.MediaRecorder._start(Native Method)
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698):    at android.media.MediaRecorder.start(MediaRecorder.java:805)
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698):    at com.hudg.callrec.Main$PhoneCallListener.StartRecording(Main.java:256)
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698):    at com.hudg.callrec.Main$PhoneCallListener.onCallStateChanged(Main.java:215)
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698):    at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:739)
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698):    at android.os.Handler.dispatchMessage(Handler.java:99)
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698):    at android.os.Looper.loop(Looper.java:158)
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698):    at android.app.ActivityThread.main(ActivityThread.java:5751)
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698):    at java.lang.reflect.Method.invokeNative(Native Method)
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698):    at java.lang.reflect.Method.invoke(Method.java:511)
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
⁃   11-18 18:37:39.973: E/AndroidRuntime(27698):    at dalvik.system.NativeStart.main(Native Method)

这是我的代码! :

public void StartRecording(){
        MediaRecorder recorder;
        recorder = new MediaRecorder();
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        recorder.setOutputFile(Environments.getExternalStorageDirectory+"test"+".AAC");
        try {
            recorder.prepare();
        } catch (Exception e) {
            // TODO: handle exception
            Log.e("MSG", "Could not Prepare Recorder !");
        }
        recorder.start();
        Log.d("MSG", "Recording finaly started !!!!!");
    }

这是新的Logcat错误! : enter image description here

2 个答案:

答案 0 :(得分:1)

您是否尝试设置其他音频编码器或输出格式?

recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

输出文件名可以通过其他方式设置,如JCasso所述:

file = FileUtil.getRecordingFile("aac").getAbsolutePath();
recorder.setOutputFile(file);

recorder.prepare();

答案 1 :(得分:0)

recorder.setOutputFile(Environments.getExternalStorageDirectory+"test"+".AAC");

输出文件名出错了。根据错误日志,您没有将其命名为“test.AAC”。

  

+ 989203626397_10 | 18 | -18:37.AAC

是有效的文件名。

编辑: 还要确保sdcard未安装到pc。