IllegalStateException when MediaCodec.configure Android

强颜欢笑 提交于 2019-12-01 16:27:10
fadden

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!