android – setOutputFormat在无效状态下调用:4(where和why)

前端之家收集整理的这篇文章主要介绍了android – setOutputFormat在无效状态下调用:4(where和why)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下代码
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);

代码执行后,我在日志中看到以下内容;

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”).所以现在我不知道导致错误的原因,我对错误发生的地方感到困惑.

编辑:我刚刚调试了调试器中的代码 – 确实在调用setProfile(profile)期间发生了错误…所以看起来调用setOutputFormat(在“C”和“D”之间)一定工作正常,但是setProfile本身必须再次调用setOutputFormat然后失败…是什么发生了?

编辑:无效状态4实际上意味着什么?是否有某些列表告诉您每个可能的无效状态号1,2,3,4等的含义?

解决方法

这是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设置为profile中的值.所以你的代码

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,"F");
media_recorder.setVideoFrameRate(15);

至少是无用的,也许在这些调用期间它会改变状态.试试没有它.

猜你在找的Android相关文章