录制视频时出现音频问题
我可以录制视频,但没有获得该视频的音频。 谁能帮我同时录制视频和音频。 我的代码如下:
mr = new MediaRecorder();
mr.setAudioSource(MediaRecorder.AudioSource.MIC);
mr.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mr.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mr.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mr.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
mPreview = new Preview(RecordVideo.this,mr);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
当我放置audioSource和audioEncoder时,它出现运行时错误: 日志猫详细信息是:
05-07 10:17:01.175: ERROR/MediaRecorder(22990): setAudioEncoder called in an invalid state(2)
05-07 10:17:01.175: ERROR/AndroidRuntime(22990): at android.media.MediaRecorder.setAudioEncoder(Native Method)
当我从代码中删除这些audioSource和audioEncoder时,它对于没有音频的视频工作正常。 我还需要音频和视频 提前致谢:
I am able to record video but I am not getting audio for that video.
Can any one help me to record video&audio at same time.
my code is as follows:
mr = new MediaRecorder();
mr.setAudioSource(MediaRecorder.AudioSource.MIC);
mr.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mr.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mr.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mr.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
mPreview = new Preview(RecordVideo.this,mr);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
when I put audioSource and audioEncoder its getting runtime error:
log cat details are:
05-07 10:17:01.175: ERROR/MediaRecorder(22990): setAudioEncoder called in an invalid state(2)
05-07 10:17:01.175: ERROR/AndroidRuntime(22990): at android.media.MediaRecorder.setAudioEncoder(Native Method)
when I remove those audioSource and audioEncoder from code its working fine for video without audio.
I need to have audio also with video
thanks in advance:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在
setOutputFormat()
之后调用setAudioEncoder()
。You should call
setAudioEncoder()
aftersetOutputFormat()
.