Android的媒体录制:java.lang.RuntimeException的:启动失败 [英] Android Media Recording: java.lang.RuntimeException: start failed

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

问题描述

我的工作记录了一个电话。当我开始记录一个电话,然后它的不幸停止。 &放大器;它提供了错误的 MediaRecorder启动失败-2147483648 。我指的这个答案链接。但我不明白。请告诉我什么是我的code中的问题?这是我的code。

 公共类IncomingCall扩展的BroadcastReceiver {

语境pcontext;
私有静态MediaRecorder记录;
私人布尔recordedStart = FALSE;

@燮pressWarnings(未登记)
公共无效的onReceive(上下文的背景下,意图意图){
    pcontext =背景;
    记录=新MediaRecorder();

尝试 {
            TelephonyManager TMGR =(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
            MyPhoneStateListener PhoneListener =新MyPhoneStateListener();
            tmgr.listen(PhoneListener,PhoneStateListener.LISTEN_CALL_STATE);

    }赶上(例外五){
        Log.e(手机接收错误,+ E);
    }

}

私有类MyPhoneStateListener扩展PhoneStateListener {
    公共无效onCallStateChanged(INT状态,串incomingNumber){



        开关(州){
        案例TelephonyManager.CALL_STATE_RINGING:
            Log.e(MyPhoneListener,国家+来袭号:+ incomingNumber);
            Log.e(CALL_STATE_RINGING,CALL_STATE_RINGING);

            打破;

        案例TelephonyManager.CALL_STATE_OFFHOOK:

            recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
            recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.DEFAULT);
            recorder.setOutputFile(Environment.getExternalStorageDirectory()+/ MyRecorder.mp3);
            Log.e(路径,+ Environment.getExternalStorageDirectory()+/ MyRecorder.mp3);
            尝试 {
                。录音机prepare();
                recorder.start();
                recordedStart =真;
                Log.e(开始,录制开始);
            }赶上(IllegalStateException异常| IOException异常E){
                // TODO自动生成的catch块
                Log.e(错误,+ E);
            }

            打破;
        案例TelephonyManager.CALL_STATE_IDLE:
            Log.e(CALL_STATE_IDLE,CALL_STATE_IDLE);
            如果(recordedStart ==真){
                recorder.stop();
                recorder.release();
                recordedStart = FALSE;
                Log.e(停止,录音机停止);
            }
            打破;
        }
    }
}
 

}

logcat的错误

 十月五日至5日:57:23.771:E / MediaRecorder(12812):启动失败:-2147483648
10月5号至5号:57:23.771:D / AndroidRuntime(12812):关闭虚拟机
10月5号至5号:57:23.771:W / dalvikvm(12812):主题ID = 1:螺纹退出与未捕获的异常(组= 0x416bdd40)
10月5号至5号:57:23.774:E / AndroidRuntime(12812):致命异常:主要
10月5号至5号:57:23.774:E / AndroidRuntime(12812):工艺:web.revolution.autocallanswer,PID:12812
10月5号至5号:57:23.774:E / AndroidRuntime(12812):java.lang.RuntimeException的:启动失败。
10月5号至5号:57:23.774:E / AndroidRuntime(12812):在android.media.MediaRecorder.start(本机方法)
10月5号至5号:57:23.774:E / AndroidRuntime(12812):在web.revolution.autocallanswer.IncomingCall$MyPhoneStateListener.onCallStateChanged(IncomingCall.java:98)
10月5号至5号:57:23.774:E / AndroidRuntime(12812):在android.telephony.PhoneStateListener $ 2.handleMessage(PhoneStateListener.java:389)
10月5号至5号:57:23.774:E / AndroidRuntime(12812):在android.os.Handler.dispatchMessage(Handler.java:102)
10月5号至5号:57:23.774:E / AndroidRuntime(12812):在android.os.Looper.loop(Looper.java:136)
10月5号至5号:57:23.774:E / AndroidRuntime(12812):在android.app.ActivityThread.main(ActivityThread.java:5102)
10月5号至5号:57:23.774:E / AndroidRuntime(12812):在java.lang.reflect.Method.invokeNative(本机方法)
10月5号至5号:57:23.774:E / AndroidRuntime(12812):在java.lang.reflect.Method.invoke(Method.java:515)
10月5号至5号:57:23.774:E / AndroidRuntime(12812):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:785)
10月5号至5号:57:23.774:E / AndroidRuntime(12812):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
10月5号至5号:57:23.774:E / AndroidRuntime(12812):在dalvik.system.NativeStart.main(本机方法)
10月5号至5号:57:25.586:I /流程(12812):发送信号。 PID:12812 SIG:9
10月5号至5号:57:27.052:E / CALL_STATE_IDLE(13255):CALL_STATE_IDLE
 

解决方案

这个问题导致此音频源

  recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
 

不工作设备和Android上的! 更改为

  recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 

或其他来源。

你也可以通过改变recorderstart()来try / catch语句与IllegalStateException异常,异常与此相同

删除FC

 尝试{
        。录音机prepare();

    }赶上(IllegalStateException异常E){
        // TODO自动生成的catch块
        Log.d(错误,IllegalStateException异常);
    }赶上(例外五){
        // TODO自动生成的catch块
        Log.d(错误,IOException异常);
        e.printStackTrace();
    }
    尝试 {
    recorder.start();
    }赶上(例外五){

    }
 

我有这个问题我自己,这是伟大的工作电话录音,但有问题,接收语音质量是非常低的,如果你发现这个电话的解决方案,我也一样。

I am working on records a phone calls. When i start a record a phone call then it's unfortunately stop. & it's gives error MediaRecorder start fail -2147483648. I refer this answer link. But i don't understand. Please tell me what is the problem in my code? Here is my Code.

public class IncomingCall extends BroadcastReceiver {

Context pcontext;
private static MediaRecorder recorder;
private boolean recordedStart = false;

@SuppressWarnings("unchecked")
public void onReceive(Context context, Intent intent) {
    pcontext = context;
    recorder = new MediaRecorder();

try {
            TelephonyManager tmgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            MyPhoneStateListener PhoneListener = new MyPhoneStateListener();
            tmgr.listen(PhoneListener, PhoneStateListener.LISTEN_CALL_STATE);

    } catch (Exception e) {
        Log.e("Phone Receive Error", " " + e);
    }

}

private class MyPhoneStateListener extends PhoneStateListener {
    public void onCallStateChanged(int state, String incomingNumber) {



        switch (state) {
        case TelephonyManager.CALL_STATE_RINGING:
            Log.e("MyPhoneListener",state+"   incoming no:"+incomingNumber);
            Log.e("CALL_STATE_RINGING", "CALL_STATE_RINGING");

            break;

        case TelephonyManager.CALL_STATE_OFFHOOK:

            recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
            recorder.setOutputFile(Environment.getExternalStorageDirectory()+"/MyRecorder.mp3");
            Log.e("Path", ""+Environment.getExternalStorageDirectory()+"/MyRecorder.mp3");
            try {
                recorder.prepare();
                recorder.start();
                recordedStart = true;
                Log.e("Start", "Recorder Start");
            } catch (IllegalStateException | IOException e) {
                // TODO Auto-generated catch block
                Log.e("Error", ""+e);
            }

            break;
        case TelephonyManager.CALL_STATE_IDLE:
            Log.e("CALL_STATE_IDLE", "CALL_STATE_IDLE");
            if (recordedStart == true) {
                recorder.stop();
                recorder.release();
                recordedStart = false;
                Log.e("Stop", "Recorder Stop");
            }
            break;
        }
    }
}

}

Logcat Error

05-05 10:57:23.771: E/MediaRecorder(12812): start failed: -2147483648
05-05 10:57:23.771: D/AndroidRuntime(12812): Shutting down VM
05-05 10:57:23.771: W/dalvikvm(12812): threadid=1: thread exiting with uncaught exception (group=0x416bdd40)
05-05 10:57:23.774: E/AndroidRuntime(12812): FATAL EXCEPTION: main
05-05 10:57:23.774: E/AndroidRuntime(12812): Process: web.revolution.autocallanswer, PID: 12812
05-05 10:57:23.774: E/AndroidRuntime(12812): java.lang.RuntimeException: start failed.
05-05 10:57:23.774: E/AndroidRuntime(12812):    at android.media.MediaRecorder.start(Native Method)
05-05 10:57:23.774: E/AndroidRuntime(12812):    at web.revolution.autocallanswer.IncomingCall$MyPhoneStateListener.onCallStateChanged(IncomingCall.java:98)
05-05 10:57:23.774: E/AndroidRuntime(12812):    at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:389)
05-05 10:57:23.774: E/AndroidRuntime(12812):    at android.os.Handler.dispatchMessage(Handler.java:102)
05-05 10:57:23.774: E/AndroidRuntime(12812):    at android.os.Looper.loop(Looper.java:136)
05-05 10:57:23.774: E/AndroidRuntime(12812):    at android.app.ActivityThread.main(ActivityThread.java:5102)
05-05 10:57:23.774: E/AndroidRuntime(12812):    at java.lang.reflect.Method.invokeNative(Native Method)
05-05 10:57:23.774: E/AndroidRuntime(12812):    at java.lang.reflect.Method.invoke(Method.java:515)
05-05 10:57:23.774: E/AndroidRuntime(12812):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
05-05 10:57:23.774: E/AndroidRuntime(12812):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
05-05 10:57:23.774: E/AndroidRuntime(12812):    at dalvik.system.NativeStart.main(Native Method)
05-05 10:57:25.586: I/Process(12812): Sending signal. PID: 12812 SIG: 9
05-05 10:57:27.052: E/CALL_STATE_IDLE(13255): CALL_STATE_IDLE

解决方案

this problem causing by this Audio source

   recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);

not working on your device and android! change that to

   recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

or other sources.

also you can remove FC by change recorderstart() to try/catch with IllegalStateException,Exception same as this

        try {
        recorder.prepare();

    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        Log.d("ERROR ","IllegalStateException");
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Log.d("ERROR ","IOException");
        e.printStackTrace();
    } 
    try {
    recorder.start();
    } catch (Exception e) {

    }

i had this problem my self,this is working great for call recording but having problem with receiver voice quality is very low if you find solution of this tel me too.

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

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