Android video recording - IllegalStateException on mediaRecorder.start

后端 未结 2 1630
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-22 05:31

I am following the tutorial on https://developer.android.com/guide/topics/media/camera.html#capture-video

As such I follow the below order when trying to start the camer

相关标签:
2条回答
  • 2021-01-22 06:11

    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.

    0 讨论(0)
  • 2021-01-22 06:12

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

    0 讨论(0)
提交回复
热议问题