本文介绍了IllegalStateException异常时,媒体codec.configure的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试建立连接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();

解决方案

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 by createEncoderByType().

这篇关于IllegalStateException异常时,媒体codec.configure的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 04:28