IllegalStateException异常时,媒体codec.configure的Android [英] IllegalStateException when MediaCodec.configure Android
问题描述
我尝试建立连接codeR为音频/ 3GPP和我的应用程序崩溃...
我用这个code
字符串mMime =音频/ 3GPP
媒体codeC MMEDIA codeC =媒体codec.createEn coderByType(mMime);
MediaFormat mMediaFormat = MediaFormat.createAudioFormat(mMime,RECORDER_SAMPLERATE,1);
MMEDIA codec.configure(mMediaFormat,NULL,NULL,媒体codec.CONFIGURE_FLAG_EN code);
MMEDIA codec.start();
异常
结果java.lang.IllegalStateException
结果android.media.Media codec.native_configure(本机方法)
结果在android.media.Media codec.configure(媒体codec.java:256)
结果在com.agent.mobile.TestAppActivity.initMedia codeC(TestAppActivity.java:234)
块引用>解决方案有必须在格式设置一些强制性值。如果你看一下文档为MediaFormat ,它说:所有键不可选的标记是强制性的。如果您没有设置强制关键,因为它已经在非法状态下被留
媒体codeC
抛出一个错误。地址:
mMediaFormat.setInteger(MediaFormat.KEY_BIT_RATE,<比特率>);
mMediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE,<样品速率GT);
mMediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT,1);
KEY_MIME
应已在createEn coderByType为您设置()
。I try create encoder for "audio/3gpp" and my app crash...
I use this code
String mMime = "audio/3gpp"; MediaCodec mMediaCodec = MediaCodec.createEncoderByType(mMime); MediaFormat mMediaFormat = MediaFormat.createAudioFormat(mMime, RECORDER_SAMPLERATE, 1); mMediaCodec.configure(mMediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE); mMediaCodec.start();
Exception
java.lang.IllegalStateException
android.media.MediaCodec.native_configure(Native Method)
at android.media.MediaCodec.configure(MediaCodec.java:256)
at com.agent.mobile.TestAppActivity.initMediaCodec(TestAppActivity.java:234)
解决方案There are some mandatory values that must be set in the format. If you look at the docs for MediaFormat, it says "all keys not marked optional are mandatory". If you fail to set a mandatory key,
MediaCodec
throws an error because it has been left in an illegal state.Add:
mMediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, <bit rate>); mMediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, <sample rate>); mMediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
KEY_MIME
should have been set for you bycreateEncoderByType()
.这篇关于IllegalStateException异常时,媒体codec.configure的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!