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

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

问题描述

我在 MediaCodec.configure() 行上收到 IllegalStateException,我正在尝试使用 MediaCodec 录制音频.这只发生在某些手机上,在标签上一切都很好.这个特定的崩溃示例来自三星 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) 的某些三星设备上尝试配置视频编解码器时,我看到了同样的错误.在很多情况下,在格式参数中将 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天全站免登陆