启动失败java.lang,java.lang.RuntimeException:启动失败

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.

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)

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> this piece of code failing in only specific devices. Am I missing any additional permissions?

解决方案

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);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值