Android video recording - IllegalStateException on mediaRecorder.start

拟墨画扇 提交于 2019-12-01 22:48:55
Edson Menegatti

Comparing agains my code, it seems you're missing two calls:

mediaRecorder.setVideoSize(int width, int height)
mediaRecorder.setPreviewDisplay(SurfaceHolder surfaceHolder)

The latter is most likely to be causing the crash as Android requires a valid preview surface to start recording. This is done so to prevent hidden cameras apps.

There are dozens of questions related to recording without a preview surface, but this one seems to sum up what you need to do to bypass this restriction. The basic idea is to resize your surface to be 1x1 and pass it to your mediaRecorder instance. Keep in mind that this may not work in all devices though.

If you are accessing mic hardware multiple times, like, using MediaRecorder and AudioRecord classes at a time will also make this exception.

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