首页 > 编程知识 正文

您的系统不支持camera raw,type recorder

时间:2023-05-04 23:24:40 阅读:240939 作者:4848

最近在学习使用camera2录制视频时发生报错:

E/MediaRecorder: prepare failed: -2147483648

比较神奇的是在android studio上自带的模拟器是不会出这个错的,但是视频不能自己保存。在我自己的华为手机上则直接报错,报错地址指向MediaRecorder的prepare方法。

首先我们看MediaRecorder的源码内容

/** * Prepares the recorder to begin capturing and encoding data. This method * must be called after setting up the desired audio and video sources, * encoders, file format, etc., but before start(). * * @throws IllegalStateException if it is called after * start() or before setOutputFormat(). * @throws IOException if prepare fails otherwise. */ public void prepare() throws IllegalStateException, IOException

需要注意的是在调用start方法之后、或者在setOutputFormat方法之前调用prepare方法均会报IllegalStateException

(这里简单提一下,在同一个按钮中实现开启录像和停止录像而不注意时序的话,可能会导致在录像开启的瞬间关闭,因而无法保存。解决方法也很简单,检测两次调用方法的时间,小于一秒直接跳过就好了)

最后在官方的指导代码里找到了这一段

/** * In this sample, we choose a video size with 3x4 aspect ratio. Also, we don't use sizes * larger than 1080p, since MediaRecorder cannot handle such a high-resolution video. * * @param choices The list of available sizes * @return The video size */ private static Size chooseVideoSize(Size[] choices)

简单翻译一下:“在此例中,我们选择一个3*4的录像并且我们不会使用大于1080p的尺寸,因为MediaRecorder不能处理如此大的视频。”

修改录像size为1080p后问题解决。

最后附上我的代码MyCamera

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。