尝试在android中录制语音但出现错误 [英] Trying to record voice in android but getting error

查看:97
本文介绍了尝试在android中录制语音但出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在android仿真器(android 4.1)中录制语音.

I am trying to record voice in android emulator (android 4.1).

但是,当我按下按钮开始录制时,它立即从函数中返回并执行下一行,记录一条记录为已录制"的消息.

But I when I press the button to start recording then it immediately return from the function and executes next line that logs a message saying "Recorded".

然后,我按停止按钮,并且在Logcat消息中显示媒体记录器因未处理的事件而消失.

Then, I press the stop button and in Logcat message appears that media recorder went away with unhandled events.

如果再次按下该按钮开始录制,则会收到一条错误消息,提示FATAL SIGNAL11.并且我不知道如何访问SD卡以查看文件是否已创建.

If I again press the button to start recording then I get an error message saying FATAL SIGNAL 11. And I dont know how to access the SD card to see if the file is created or not.

下面是我在教程中使用的logCat代码:

Below is the logCat code that I used from a tutorial:

}

  public void start() throws IOException {
    String state = android.os.Environment.getExternalStorageState();
    if(!state.equals(android.os.Environment.MEDIA_MOUNTED))  {
        throw new IOException("SD Card is not mounted.  It is " + state + ".");
    }

    // make sure the directory we plan to store the recording in exists
    File directory = new File(path).getParentFile();
    if (!directory.exists() && !directory.mkdirs()) {
      throw new IOException("Path to file could not be created.");
    }

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setOutputFile(path);
    try{
    recorder.prepare();
    }
    catch(IOException e){
        Log.e("Recorder","Recording failed");
    }
    recorder.start();
  }
  /**
   * Stops a recording that has been previously started.
   */
  public void stop() throws IOException {
    recorder.stop();
    recorder.release();
  }

logCat是:

08-08 16:09:39.713:D/gralloc_goldfish(743):未检测到GPU仿真的仿真器.

08-08 16:09:39.713: D/gralloc_goldfish(743): Emulator without GPU emulation detected.

08-08 16:09:42.674:D/Recorder(743):已记录

08-08 16:09:42.674: D/Recorder(743): Recorded

08-08 16:09:48.764:W/MediaRecorder(743):mediarecorder因未处理的事件而消失

08-08 16:09:48.764: W/MediaRecorder(743): mediarecorder went away with unhandled events

08-08 16:13:01.613:A/libc(743):致命信号11(SIGSEGV)位于0x00000010(代码= 1),线程743(xample.recorder)

08-08 16:13:01.613: A/libc(743): Fatal signal 11 (SIGSEGV) at 0x00000010 (code=1), thread 743 (xample.recorder)

推荐答案

我通过在释放记录器之前使其静止来解决此问题.

I solved this problem by resting recorder before releasing it.

        recorder.stop();//stop recording
        recorder.reset();
        recorder.release();

这篇关于尝试在android中录制语音但出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆