java.lang.RuntimeException:启动失败 [英] java.lang.RuntimeException: start failed

查看:1372
本文介绍了java.lang.RuntimeException:启动失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MediaRecorder在我的一个Activity中录制音频.部分代码如下所示.

I am trying to record audio in one of my Activities using MediaRecorder. Part of the code is shown below.

File file = new File(AppConstants.MSGS_DIR, filename);
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(AudioSource.MIC);
recorder.setOutputFormat(OutputFormat.THREE_GPP);
recorder.setAudioEncoder(AudioEncoder.AMR_WB);
recorder.setOutputFile(file.getAbsolutePath());
try {
    recorder.prepare();
    recorder.start();
} catch (IOException e) {
    System.out.println("Exception: " + e.getMessage());
}

我在清单文件中授予了以下权限.

I've given the following permissions in manifest file.

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

但是在 recorder.start()行中,我遇到了运行时异常. Logcat显示以下错误消息.

but at the line recorder.start() I am getting the runtime exception. Logcat shows the following error messages.

09-23 15:47:54.462: E/AndroidRuntime(8697): FATAL EXCEPTION: main
09-23 15:47:54.462: E/AndroidRuntime(8697): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage/com.mypackage.RecordingActivity}: java.lang.RuntimeException: start failed.
09-23 15:47:54.462: E/AndroidRuntime(8697):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2250)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2300)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at android.app.ActivityThread.access$600(ActivityThread.java:144)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1295)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at android.os.Looper.loop(Looper.java:150)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at android.app.ActivityThread.main(ActivityThread.java:5162)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at java.lang.reflect.Method.invokeNative(Native Method)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at java.lang.reflect.Method.invoke(Method.java:525)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:744)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at dalvik.system.NativeStart.main(Native Method)
09-23 15:47:54.462: E/AndroidRuntime(8697): Caused by: java.lang.RuntimeException: start failed.
09-23 15:47:54.462: E/AndroidRuntime(8697):     at android.media.MediaRecorder.start(Native Method)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at com.mypackage.RecordingActivity.startRecording(RecordingActivity.java:169)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at com.mypackage.RecordingActivity.onCreate(RecordingActivity.java:107)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at android.app.Activity.performCreate(Activity.java:5288)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2214)

尝试了与stackoverflow中的错误相对应的问题,但无法从中得出有效的答案.请检查此内容,并帮助我代码中哪里出了错.

Tried questions corresponding to the error in stackoverflow but unable to conclude a valid answers from them. Please check this and help me which is going wrong in the code.

FYI>这段代码仅在特定设备中失败.我是否还缺少其他权限?

FYI> this piece of code failing in only specific devices. Am I missing any additional permissions?

推荐答案

很少有设备不支持,因为它们不支持3GP格式以及AudioEncoder.AMR_WB编码.点击此处以检查支持的格式.

Few of the devices are not supporting because they do not support 3GP format as well as AudioEncoder.AMR_WB encoding. Click here to check the supported formats.

请使用下面的代码,该代码将支持最大数量的设备.

Please use below code which will support maximum number of devices.

recorder.setOutputFormat(OutputFormat.MPEG_4);
recorder.setAudioEncoder(AudioEncoder.AAC);

这篇关于java.lang.RuntimeException:启动失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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