调用MediaCodec.configure()时出现非法状态异常 [英] Illegal State Exception when calling MediaCodec.configure()

查看:902
本文介绍了调用MediaCodec.configure()时出现非法状态异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MediaCodec.configure()行上收到IllegalStateException,我正在尝试使用MediaCodec录制音频.这仅发生在某些手机上,在选项卡上一切正常.这个特定的崩溃示例来自Samsung Galaxy S4. 异常痕迹:

I get the IllegalStateException on MediaCodec.configure() line, I'm trying to record audio using MediaCodec. This only occur on some phones, on tabs everything is fine. This particular crash example is from Samsung Galaxy S4. Exception traces:

01-22 17:33:38.379: V/ACodec(16541): [OMX.google.aac.decoder] Now Loaded
01-22 17:33:38.379: V/ACodec(16541): onConfigureComponent
01-22 17:33:38.379: W/ACodec(16541): [OMX.google.aac.decoder] Failed to set standard component role 'audio_encoder.aac'.
01-22 17:33:38.379: E/ACodec(16541): [OMX.google.aac.decoder] configureCodec returning error -2147483648
01-22 17:33:38.379: E/MediaCodec(16541): Codec reported an error. (omx error 0x80001001, internalError -2147483648)
01-22 17:33:38.384: D/AndroidRuntime(16541): Shutting down VM
01-22 17:33:38.384: W/dalvikvm(16541): threadid=1: thread exiting with uncaught exception (group=0x418d0700)
01-22 17:33:38.414: W/BugSenseHandler(16541): Transmitting crash Exception Unable to resolve host "bugsense.appspot.com": No address associated with hostname
01-22 17:33:41.404: E/AndroidRuntime(16541): FATAL EXCEPTION: main
01-22 17:33:41.404: E/AndroidRuntime(16541): java.lang.IllegalStateException
01-22 17:33:41.404: E/AndroidRuntime(16541):    at android.media.MediaCodec.native_configure(Native Method)
01-22 17:33:41.404: E/AndroidRuntime(16541):    at android.media.MediaCodec.configure(MediaCodec.java:259)
01-22 17:33:41.404: E/AndroidRuntime(16541):    at com.example.poc.MyRenderer.startRecordPressed(MyRenderer.java:344)

音频格式声明:

    MediaFormat format = new MediaFormat();
    format.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
    format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    format.setInteger(MediaFormat.KEY_SAMPLE_RATE, 44100);
    format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
    format.setInteger(MediaFormat.KEY_BIT_RATE, 64000);

音频编码器初始化:

        mAudioEncoder = MediaCodec.createEncoderByType("audio/mp4a-latm");
        mAudioEncoder.configure(mAudioFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE); //<-This line fails
        mAudioEncoder.start();

有人知道这可能是什么吗?奇怪的是,它仅在某些设备上发生. 任何建议都将受到欢迎!

Does anyone have any idea what that might be? What's strange is that it only happens on some devices. Any suggestions would be welcome!

推荐答案

在尝试在运行Jellybean(4.1.2)的某些Samsung设备上配置视频编解码器时,我看到了相同的错误.在许多情况下,将format参数中的KEY_MAX_INPUT_SIZE设置为0(在调用configure之前)将解决此问题:

I see this same error when trying to configure a video codec on certain Samsung devices running Jellybean (4.1.2). In many cases, setting KEY_MAX_INPUT_SIZE to 0 (before calling configure) in the format parameters will fix it:

mVideoFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 0);

我在研究类似错误时发现了此解决方案( https://stackoverflow.com/questions /15105843/mediacodec-jelly-bean# = ),并且对此功能解决了许多编解码器配置错误感到惊讶.就是说,我还没有在音频编解码器上尝试过它,所以不能保证它会在您的情况下起作用:/

I found this solution when researching a similar bug (https://stackoverflow.com/questions/15105843/mediacodec-jelly-bean#=), and have been surprised at how many codec configuration bugs this fixes. That said, I haven't tried it on Audio codecs so no guarantee it will work in your case :/

这篇关于调用MediaCodec.configure()时出现非法状态异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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