问题描述
我试图建立在Android录像机,我已经prepared我的code这应该是工作 - 但我不断地得到一个错误信息启动失败:-19
I'm trying to create a video recorder on Android, and I've prepared my code which is supposed to be working - but I constantly get an error message start failed: -19
.
下面是我的code:
public boolean startRecording() {
try {
camera.unlock();
mediaRecorder = new MediaRecorder();
mediaRecorder.setOnErrorListener(new MediaRecorder.OnErrorListener() {
@Override
public void onError(MediaRecorder mr, int what, int extra) {
Log.i(TAG, "Error");
}
});
mediaRecorder.setCamera(camera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
Log.i(TAG, "a");
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
Log.i(TAG, "b");
mediaRecorder.setMaxDuration(maxDurationInMs); // set to 20000
String uniqueOutFile = OUTPUT_FILE + System.currentTimeMillis() + ".3gp";
File outFile = new File(uniqueOutFile);
if (outFile.exists()) {
outFile.delete();
}
mediaRecorder.setOutputFile(uniqueOutFile);
mediaRecorder.setVideoFrameRate(videoFramesPerSecond); // set to 20
mediaRecorder.setVideoSize(sView.getWidth(), sView.getHeight());
Log.i(TAG, "c");
mediaRecorder.setPreviewDisplay(holder.getSurface());
mediaRecorder.setMaxFileSize(maxFileSizeInBytes); // set to 50000
mediaRecorder.prepare();
Log.i(TAG, "d");
mediaRecorder.start();
Log.i(TAG, "e");
return true;
} catch (IllegalStateException e) {
Log.i(TAG, "f");
Log.e(TAG, e.getMessage());
e.printStackTrace();
camera.lock();
return false;
} catch (IOException e) {
Log.i(TAG, "g");
Log.e(TAG, e.getMessage());
e.printStackTrace();
camera.lock();
return false;
} catch (RuntimeException e) {
Log.i(TAG, "h");
Log.e(TAG, e.getMessage());
camera.lock();
return false;
}
}
所有(从A到D)的调试日志打印日志,因此它似乎是高达 mediaRecorder。prepare所有步骤()
正确完成。然后抓住一个的RuntimeException
有消息启动失败:-19
。有一个类似question,但是,这并不解决我的问题。
All the debug logs (from "a" through "d") are printed in log, so it seems that all the steps upto mediaRecorder.prepare()
are properly done. Then it catches a RuntimeException
with message start failed: -19
. There is a similar question, but that doesn't solve my problem.
有没有其他原因让这样的错误?
Is there any other reason to get such an error?
推荐答案
刚刚发现的BUG,在这一行:
Just found out the bug, in this line:
mediaRecorder.setVideoSize(sView.getWidth(), sView.getHeight());
注释掉这一行之后,code完美运行!
after commenting out this line, the code runs perfectly!
这篇关于Android的MediaRecorder - "启动失败:-19"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!