问题
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:
回答1:
You should call setAudioEncoder()
after setOutputFormat()
.
来源:https://stackoverflow.com/questions/5909382/problem-with-audio-while-recording-video