private voID startRecordingVIDeo() { recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setVIDeoSource(MediaRecorder.VIDeoSource.CAMERA); recorder.setoutputFormat(MediaRecorder.OutputFormat.MPEG_4); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setVIDeoEncoder(MediaRecorder.VIDeoEncoder.DEFAulT); file file = getAlbumDir(); recorder.setoutputfile(file.getabsolutePath()); recorder.setMaxDuration(50000); recorder.setMaxfileSize(5000000); recorder.setPrevIEwdisplay(CameraBrIDgeVIEwBase.surfaceHolder.getSurface()); try { recorder.prepare(); recorder.start(); } catch (IllegalStateException | IOException e) { e.printstacktrace(); } }
现在这给了我MediaRecorder:启动失败:-19错误.我检查了this和this链接,它们表示要删除mediaRecorder.setVIDeoSize(sVIEw.getWIDth(),sVIEw.getHeight());但我没有使用setVIDeoSize(sVIEw.getWIDth(),sVIEw.getHeight()).有了尝试和错误,我发现如果我删除编码器recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);和recorder.setVIDeoEncoder(MediaRecorder.VIDeoEncoder.DEFAulT);应用程序不会崩溃,但会给出新的异常:
03-23 16:50:06.213 28226-28226/com.scenera.androID.surveillance E/MediaRecorder: audio source is set,but audio encoder is not set
我不明白我在这里做错了什么.任何帮助都会得到满足.提前致谢.
解决方法 问题是你没有设置相机,使用Camera 1 API,你应该先打开相机,然后将其解锁并将其设置到录像机.只有在那之后你才能继续配置MediaRecorder(这是一个非常漂亮的API写的)MediaRecorder recorder = new MediaRecorder();Camera camera = Camera.open();camera.unlock();recorder.setCamera(camera);recorder.setPrevIEwdisplay(surfaceHolder.getSurface());recorder.setAudioSource(MediaRecorder.AudioSource.MIC);recorder.setVIDeoSource(MediaRecorder.VIDeoSource.CAMERA);recorder.setoutputFormat(MediaRecorder.OutputFormat.MPEG_4);recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);recorder.setVIDeoEncoder(MediaRecorder.VIDeoEncoder.DEFAulT);file file = getAlbumDir();recorder.setoutputfile(file.getabsolutePath());recorder.setMaxDuration(50000);recorder.setMaxfileSize(5000000);try { recorder.prepare(); recorder.start();} catch (IllegalStateException | IOException e) { e.printstacktrace();}总结
以上是内存溢出为你收集整理的android – MediaRecorder给出启动错误或IllegalStateException全部内容,希望文章能够帮你解决android – MediaRecorder给出启动错误或IllegalStateException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)