天天看点

Android MediaMuxer使用遇到的问题

1.IllegalStateException问题 MediaMuxer的使用必须严格遵循如下顺序: addTrack->start->writeSampleData->stop->release 如果有顺序冲突或者多次调用start、stop、release,会导致IllegalStateException 在使用MediaMuxer时,经常遇到的场景是在两个不同的Thread中分别执行音视频的录制+编码,所以需要等待两个线程都执行完addTrack之后,再start

2.stop fail的问题 addTrack的时候,传入的MediaFormat需要从对应的MediaCodec实例调用MediaCodec.getOutputFormat()得到,否则stop的时候会发生Exception