本文介绍了MediaRecorder扔"了java.lang.RuntimeException:启动失败:-2147483648"要记录在LG G观看音频时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的一个LG G观看的应用程序录制音频。下面code抛出的RuntimeException与消息启动失败:-2147483648的声明recorder.start();。想知道我在做什么错在这里。

我已经尝试了很多不同的参数,例如为AudioSource:

  recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
//-和-
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

也为OUTPUTFORMAT我曾尝试

  recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
//-和-
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
//-和-
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

也尝试了不同的AudioEn codeR

  recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.DEFAULT);
//-和-
recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.AMR_NB);

下面是源$ C ​​$ C:

 最后MediaRecorder记录=新MediaRecorder();
            recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
            recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.DEFAULT);
            //recorder.setAudioSamplingRate(8000); //尝试使用和不使用这条线
            字符串文件名= mMainActivity.getExternalFilesDir(空)+/my_recording.mp4 //改成相应的扩展名的输出格式
            Log.d(调试,输出文件名=+文件名);
            recorder.setOutputFile(文件名);
            尝试{
                。录音机prepare();
            }
            赶上(IOException异常五){
                Log.d(调试,IOException异常而prepare():+ e.getMessage());
            }
            尝试{
                视频下载(1000);
            }赶上(InterruptedException的E){
                Log.d(调试,InterruptedException的同时Thread.sleep()方法:+ e.getMessage());
            }
            Log.d(调试,开始前);
            尝试{
                recorder.start(); //< ---异常抛出这里
            }
            赶上(IllegalStateException异常五){
                Log.d(调试,IllegalStateException异常而开始():+ e.getMessage());
            }
            Log.d(调试,启动后);

------------编辑--------------------

下面是logcat的输出:

 一月9日至22日:33:10.697 8764-8764 / com.company.project D / DEBUG:输出文件名= /storage/emulated/0/Android/data/com.company的.project /文件/ my_recording.mp4
1月9日至22日:33:11.697 8764-8764 / com.company.project D / DEBUG:开始之前
1月9日至22日:33:11.707 8764-8764 / com.company.project E / MediaRecorder:启动失败:-2147483648
1月9日至22日:33:11.707 8764-8764 / com.company.project D / AndroidRuntime:关闭VM
1月9日至22日:33:11.707 8764-8764 / com.company.project W / dalvikvm:主题ID = 1:螺纹未捕获的异常退出(组= 0xada14d70)
1月9日至22日:33:11.737 8764-8764 / com.company.project E / AndroidRuntime:致命异常:主要
工艺:com.company.project,PID:8764
了java.lang.RuntimeException:启动失败。
        在android.media.MediaRecorder.start(本机方法)
        在com.company.project.MainActivity $ 1.onLayoutInflated(MainActivity.java:56)
        在android.support.wearable.view.WatchViewStub.inflate(WatchViewStub.java:133)
        在android.support.wearable.view.WatchViewStub.onMeasure(WatchViewStub.java:141)
        在android.view.View.measure(View.java:16648)
        在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        在android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        在android.view.View.measure(View.java:16648)
        在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        在android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        在com.android.internal.policy.impl.PhoneWindow $ DecorView.onMeasure(PhoneWindow.java:2338)
        在android.view.View.measure(View.java:16648)
        在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1959)
        在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1145)
        在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1396)
        在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1032)
        在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:5657)
        在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:761)
        在android.view.Choreographer.doCallbacks(Choreographer.java:574)
        在android.view.Choreographer.doFrame(Choreographer.java:544)
        在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:747)
        在android.os.Handler.handleCallback(Handler.java:733)
        在android.os.Handler.dispatchMessage(Handler.java:95)
        在android.os.Looper.loop(Looper.java:136)
        在android.app.ActivityThread.main(ActivityThread.java:5026)
        在java.lang.reflect.Method.invokeNative(本机方法)
        在java.lang.reflect.Method.invoke(Method.java:515)
        在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:777)
        在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
        在dalvik.system.NativeStart.main(本机方法)
1月9日至22日:33:11.777 8764-8764 / com.company.project I /工艺:发送信号。 PID:8764 SIG:9

请注意:我有以下权限在我的清单:

 <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
<使用许可权的android:NAME =android.permission.RECORD_AUDIO/>

我的环境是:

  SDK:API 20:Android 4.4系统(奇巧磨损)
构建工具:19.1.0
Android的工作室:0.8.9


解决方案

您不能在Android Wear,只有AudioRecord使用MediaRecorder。
在这里,YouTube视频,其中谷歌的开发人员在谈论语音识别它们是如何录制的音频:

<一个href=\"https://www.youtube.com/watch?v=sha_w3_5c2c#t=1970\">https://www.youtube.com/watch?v=sha_w3_5c2c#t=1970

I am trying to record audio in my app on a LG G Watch. The following code throws RuntimeException with message "start failed: -2147483648" at the statement "recorder.start();". Wondering what I'm doing wrong here.

I have tried a lot of different set of parameters, for example for AudioSource:

recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
//-and-
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

Also for OutputFormat I have tried

recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
//-and-
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
//-and-
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

Also tried different AudioEncoder

recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
//-and-
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

Here is the source code:

            final MediaRecorder recorder = new MediaRecorder();
            recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
            //recorder.setAudioSamplingRate(8000);  // tried with and without this line
            String filename = mMainActivity.getExternalFilesDir(null) + "/my_recording.mp4"; // changed to corresponding extension name for the output format
            Log.d("DEBUG", "Output filename = " + filename);
            recorder.setOutputFile(filename);
            try {
                recorder.prepare();
            }
            catch (IOException e) {
                Log.d("DEBUG", "IOException while prepare(): " + e.getMessage());
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Log.d("DEBUG", "InterruptedException while Thread.sleep(): " + e.getMessage());
            }
            Log.d("DEBUG", "before start");
            try {
                recorder.start(); // <--- exception is thrown here
            }
            catch (IllegalStateException e) {
                Log.d("DEBUG", "IllegalStateException while start(): " + e.getMessage());
            }
            Log.d("DEBUG", "after start");

------------EDIT--------------------

Here is the logcat output:

09-22 01:33:10.697    8764-8764/com.company.project D/DEBUG﹕ Output filename = /storage/emulated/0/Android/data/com.company.project/files/my_recording.mp4
09-22 01:33:11.697    8764-8764/com.company.project D/DEBUG﹕ before start
09-22 01:33:11.707    8764-8764/com.company.project E/MediaRecorder﹕ start failed: -2147483648
09-22 01:33:11.707    8764-8764/com.company.project D/AndroidRuntime﹕ Shutting down VM
09-22 01:33:11.707    8764-8764/com.company.project W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xada14d70)
09-22 01:33:11.737    8764-8764/com.company.project E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.company.project, PID: 8764
java.lang.RuntimeException: start failed.
        at android.media.MediaRecorder.start(Native Method)
        at com.company.project.MainActivity$1.onLayoutInflated(MainActivity.java:56)
        at android.support.wearable.view.WatchViewStub.inflate(WatchViewStub.java:133)
        at android.support.wearable.view.WatchViewStub.onMeasure(WatchViewStub.java:141)
        at android.view.View.measure(View.java:16648)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at android.view.View.measure(View.java:16648)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2338)
        at android.view.View.measure(View.java:16648)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1959)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1145)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1396)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1032)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5657)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
        at android.view.Choreographer.doCallbacks(Choreographer.java:574)
        at android.view.Choreographer.doFrame(Choreographer.java:544)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5026)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
        at dalvik.system.NativeStart.main(Native Method)
09-22 01:33:11.777    8764-8764/com.company.project I/Process﹕ Sending signal. PID: 8764 SIG: 9

NOTE: I have the following permissions in my manifest:

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

My environment is:

SDK: API 20: Android 4.4 (KitKat Wear)
Build tool: 19.1.0
Android Studio: 0.8.9
解决方案

You cannot use MediaRecorder in Android Wear, Only AudioRecord.Here a YouTube video where Google developers talking about how they recording audio for speech recognition:

https://www.youtube.com/watch?v=sha_w3_5c2c#t=1970

这篇关于MediaRecorder扔&QUOT;了java.lang.RuntimeException:启动失败:-2147483648&QUOT;要记录在LG G观看音频时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 17:01