问题描述
我录制的视频与MediaRecorder。我的code正常工作的2.3.3,但无法在4.0.3。
I am recording video with MediaRecorder. My code works fine on 2.3.3 but fails on 4.0.3.
此问题是以下几种:code mediaRecorder.stop()抛出RuntimeExeption
The issue is following: the code mediaRecorder.stop() throws the RuntimeExeption
java.lang.RuntimeException: stop failed.
at android.media.MediaRecorder.stop(Native Method)
与LogCat中的消息
with LogCat message
04-05 15:10:51.815: E/MediaRecorder(15709): stop failed: -1007
更新
我发现,这MediaPlayer的报告错误(通过MediaPlayer.OnErrorListener)开始后几乎立即。错误code是100(媒体服务器去世),额外-1007。
I've found, that MediaPlayer reports an error (via MediaPlayer.OnErrorListener) almost immediately after the start. Error code is 100 (media server died), extra -1007.
更新2code至prepare的MediaRecorder
UPDATE 2Code to prepare the MediaRecorder
c = Camera.open();
...
// Step 1: Unlock and set camera to MediaRecorder
camera.unlock();
mediaRecorder.setCamera(camera);
// Step 2: Set sources
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
CamcorderProfile profile = CamcorderProfile
.get(CamcorderProfile.QUALITY_HIGH);
// manual set up!
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mediaRecorder.setVideoFrameRate(profile.videoFrameRate);
mediaRecorder.setVideoSize(profile.videoFrameWidth,
profile.videoFrameHeight);
mediaRecorder.setAudioChannels(profile.audioChannels);
mediaRecorder.setAudioEncodingBitRate(profile.audioBitRate);
mediaRecorder.setAudioSamplingRate(profile.audioSampleRate);
mediaRecorder.setAudioEncoder(profile.audioCodec);
//mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
mediaRecorder.setVideoEncoder(profile.videoCodec);
// mediaRecorder.setProfile(profile);
// Step 4: Set output file
mediaRecorder.setOutputFile("somefile.mp4");
// Step 5: Set the preview output
mediaRecorder.setPreviewDisplay(preview.getHolder().getSurface());
// Step 6: Prepare configured MediaRecorder
try {
mediaRecorder.prepare();
} catch ...
{ release mediaRecorder}
然后我simplyCall mediaRecorder.start()请注意,我需要的视频是EN $ C $的CD转换成MP4格式。这code适用于Samsng银河GIO(安卓2.3.3),未能如宏碁E305(安卓4.0.2)
then I simplyCall mediaRecorder.start()please note, that I need video to be encoded into mp4 format.This code works on Samsng Galaxy GIO (android 2.3.3) and fails as described on Acer E305 (android 4.0.2)
任何想法?谢谢你。
推荐答案
解决了最后。这个问题是设置preVIEW大小设置实际preVIEW摄像机前。在preVIEW尺寸必须等于选择的视频大小。
Solved it at last.The issue was setting the preview size before setting the actual preview for the camera. The preview size MUST be equal to the selected video size.
CamcorderProfile profile = [get required profile];
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(profile.videoFrameWidth,profile.videoFrameHeight);
mCamera.setParameters(parameters);
mCamera.setPreviewDisplay([surface holder]);
mCamera.startPreview();
...
//configure MediaRecorder and call MediaRecorder.start()
这篇关于MediaRecorder.stop()停止失败:-1007的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!