问题描述
我有以下代码:
Log.i("xx","A");
media_recorder = new MediaRecorder();
Log.i("xx","B");
media_recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
Log.i("xx","C");
media_recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
Log.i("xx","D");
media_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
Log.i("xx","E");
media_recorder.setVideoSize(320, 240);
Log.i("xx","F");
media_recorder.setVideoFrameRate(15);
Log.i("xx","G");
CamcorderProfile profile = CamcorderProfile.get(CameraInfo.CAMERA_FACING_FRONT,CamcorderProfile.QUALITY_LOW);
Log.i("xx","H");
media_recorder.setProfile(profile);
Log.i("xx","I");
media_recorder.setOutputFile(fname);
执行代码后,我在日志中看到以下内容;
When the code is executed, I see the following in my logs;
02-07 16:12:47.628: I/xx(15436): A
02-07 16:12:47.628: I/xx(15436): B
02-07 16:12:47.638: I/xx(15436): C
02-07 16:12:47.638: I/xx(15436): D
02-07 16:12:47.638: I/xx(15436): E
02-07 16:12:47.638: I/xx(15436): F
02-07 16:12:47.638: I/xx(15436): G
02-07 16:12:47.638: I/xx(15436): H
02-07 16:12:47.638: E/MediaRecorder(15436): setOutputFormat called in an invalid state: 4
这让我感到困惑,因为对 setOutputFormat
的调用是在"C"和"D"之间进行的,但是错误的报告似乎紧接在H之后(从未到达"I").所以现在我不知道是什么导致了错误,并且我对错误发生的位置感到困惑.
This has confused me because the call to setOutputFormat
was made between "C" and "D", but the report of the error appears to be immediately after H (never reaching "I"). So now I don't know what is causing the error, and I'm confused about where the error is occurring.
编辑:我只是逐步调试了调试器中的代码-并确定在调用setProfile(profile)期间发生了足够的错误...因此,似乎是对setOutputFormat的调用(在"C"和"D"之间)必须工作正常,但是setProfile必须本身再次调用setOutputFormat,然后失败...这是怎么回事?
I just stepped through the code in the debugger - and sure enough the error occurs during the call to setProfile(profile)... so it would appear that the call made to setOutputFormat (between "C" & "D") must have worked ok, but then setProfile must itself make a second call to setOutputFormat which then fails... is that what's going on?
编辑:无效状态4的实际含义是什么?某处是否有列表告诉您每个可能的无效状态编号1,2,3,4 ...等等的含义?
And what does invalid state 4 actually mean? Is there some list somewhere which tells you the meaning of each possible invalid state number 1,2,3,4...etc?
推荐答案
这是 setProfile
方法的源代码:
public void setProfile(CamcorderProfile profile) {
setOutputFormat(profile.fileFormat);
setVideoFrameRate(profile.videoFrameRate);
setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
setVideoEncodingBitRate(profile.videoBitRate);
setVideoEncoder(profile.videoCodec);
if (profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW &&
profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_QVGA) {
// Nothing needs to be done. Call to setCaptureRate() enables
// time lapse video recording.
} else {
setAudioEncodingBitRate(profile.audioBitRate);
setAudioChannels(profile.audioChannels);
setAudioSamplingRate(profile.audioSampleRate);
setAudioEncoder(profile.audioCodec);
}
}
例如它将outputFormat,videoSize,encoder和frameRate设置为配置文件中的值.所以你的代码:
E.g. it sets outputFormat, videoSize, encoder and frameRate to values from profile. So your code:
Log.i("xx","C");
media_recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
Log.i("xx","D");
media_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
Log.i("xx","E");
media_recorder.setVideoSize(320, 240);
Log.i("xx","F");
media_recorder.setVideoFrameRate(15);
至少是无用的,也许在这些调用期间它会更改状态.尝试不使用它.
is at least useless, and maybe during these calls it changes state. Try without it.
这篇关于setOutputFormat在无效状态下调用:4(在何处以及为什么)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!