Q1。我可以同时使用setVideoFrameRate和setCaptureRate吗?任何人都可以解释这些差异以及何时使用这两者中的哪一个?
Q2。以下代码流程是否正确?我 Nexus 7(2013)Android 4.3 前置摄像头 MediaRecorder启动失败:-19 错误。使用后置摄像头,相同的代码完美无缺,没有任何错误。任何人都可以更正下面的代码以及为什么它背面而不是前置摄像头?
public void saveVideo(int resX, int resY, int bitRate, int fps, Camera camera){
File tempFile = null;
MediaRecorder mediaRecorder = null;
try{
tempFile = new File("/storage/emulated/0/Pictures/MyCameraApp/"+"_"+resX+"x"+resY+"_"+bitRate+"_"+fps+".mp4");
mediaRecorder = new MediaRecorder();
camera.unlock();
mediaRecorder.setCamera(camera);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mediaRecorder.setVideoSize(resX, resY);
mediaRecorder.setVideoFrameRate(fps);
//mediaRecorder.setCaptureRate(fps);
mediaRecorder.setVideoEncodingBitRate(bitRate);
mediaRecorder.setOnErrorListener(new MediaRecorder.OnErrorListener()
{
@Override
public void onError(MediaRecorder mr, int what, int extra) {
Log.i("MainActivity", "MediaRecorder Error");
}
});
mediaRecorder.setOutputFile(tempFile.toString());
mediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
mediaRecorder.prepare();
mediaRecorder.start();
Thread.sleep(5000); // Recording for 1 second
}
catch (InterruptedException interrptedException ) {
}
catch ( IOException ioException){
}
catch(IllegalStateException illegalState){
}
if (mediaRecorder != null) {
try {
mediaRecorder.stop();
}
catch (IllegalStateException illegal){
}
mediaRecorder.reset(); // clear recorder configuration
mediaRecorder.release(); // release the recorder object
mediaRecorder = null;
}
camera.lock();
}
答案 0 :(得分:0)
setCaptureRate
用于延时案例。 setVideoFrameRate
用于正常记录案例。
如果setCaptureRate
失败,可能您的设备不支持延时模式。