android – 由于recorder.setAudioSource(MediaRecorder.AudioSource.MIC)导致的Forceclose错误;

android – 由于recorder.setAudioSource(MediaRecorder.AudioSource.MIC)导致的Forceclose错误;,第1张

概述我正在创建一个录音机应用程序,我一整天都在谷歌搜索,我发现了一些可用于录制音频的代码.但每次我运行代码时,我的应用程序都会发出强制关闭错误并关闭. 我发现的代码如下 MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); ***<== ERR 我正在创建一个录音机应用程序,我一整天都在谷歌搜索,我发现了一些可用于录制音频的代码.但每次我运行代码时,我的应用程序都会发出强制关闭错误并关闭.
我发现的代码如下

MediaRecorder recorder = new MediaRecorder();    recorder.setAudioSource(MediaRecorder.AudioSource.MIC); ***<== ERROR***    recorder.setoutputFormat(MediaRecorder.OutputFormat.THREE_GPP);    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);    recorder.setoutputfile("/sdcard/sample.3gp");    recorder.setonErrorListener(errorListener);    recorder.setonInfoListener(infoListener);    try {        recorder.prepare();        recorder.start();    } catch (IllegalStateException e) {        e.printstacktrace();    } catch (IOException e) {        e.printstacktrace();    }

我正在使用AndroID API 2.1

解决方法 您可以找到最好的例子: http://developer.android.com/guide/topics/media/index.html#capture

我希望你在手机上测试它,因为:

Note that the emulator doesn’t have harDWare to capture audio or vIDeo,but actual mobile devices are likely to provIDe these capabilitIEs,accessible through the MediaRecorder class.

看看这个:

/* * The application needs to have the permission to write to external storage * if the output file is written to the external storage,and also the * permission to record audio. These permissions must be set in the * application's AndroIDManifest.xml file,with something like: * * <uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE" /> * <uses-permission androID:name="androID.permission.RECORD_AUdio" /> */
总结

以上是内存溢出为你收集整理的android – 由于recorder.setAudioSource(MediaRecorder.AudioSource.MIC)导致的Forceclose错误;全部内容,希望文章能够帮你解决android – 由于recorder.setAudioSource(MediaRecorder.AudioSource.MIC)导致的Forceclose错误;所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1121775.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存