我录制的视频与MediaRecorder。 我的代码工作正常,在2.3.3,但未能在4.0.3。
问题是以下几点:代码mediaRecorder.stop()抛出的RuntimeExeption
java.lang.RuntimeException: stop failed.
at android.media.MediaRecorder.stop(Native Method)
与logcat的消息
04-05 15:10:51.815: E/MediaRecorder(15709): stop failed: -1007
UPDATE
我发现,MediaPlayer的开始后报告错误(通过MediaPlayer.OnErrorListener)几乎立即。 错误代码是100(媒体服务器去世),额外-1007。
更新2代码编写的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()请注意,我需要的视频被编码成MP4格式。 此代码的工作就Samsng银河GIO(安卓2.3.3),但无法作为宏碁E305(安卓4.0.2)中描述
有任何想法吗? 谢谢。