【发布时间】:2012-08-05 12:03:17
【问题描述】:
我正在尝试在 android 模拟器 (android 4.1) 中录制语音。
但是当我按下按钮开始录制时,它会立即从函数返回并执行下一行记录一条消息“已录制”。
然后,我按下停止按钮,在 Logcat 消息中出现媒体记录器因未处理的事件而消失。
如果我再次按下按钮开始录制,则会收到一条错误消息,提示 FATAL SIGNAL 11。而且我不知道如何访问 SD 卡以查看文件是否已创建。
以下是我在教程中使用的 logCat 代码:
}
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:42.674:D/Recorder(743):记录
08-08 16:09:48.764:W/MediaRecorder(743):mediarecorder 因未处理的事件而消失
08-08 16:13:01.613:A/libc(743):致命信号 11 (SIGSEGV) 位于 0x00000010 (code=1),线程 743 (xample.recorder)
【问题讨论】:
-
请复制并粘贴 Logcat 文本而不是图像。
-
您是否在清单中设置了所需的权限?
-
我正在使用 android.permission.RECORD_AUDIO 和 android.permission.WRITE_EXTERNAL_STORAGE 权限
-
查看stackoverflow.com/questions/5254994/… 的最高评价答案中的第二段(关于 AVD 的配置。你这样做了吗?)
-
是的,我已经这样做了,但该帖子还提到“然后使用 [MediaRecorder API][1] 进行录制 (MediaRecorder.AudioSource.MIC)。”但我在 API 级别 16 工作,我可以返回的最大值是 API 级别 8