Problem with audio while recording video

妖精的绣舞 提交于 2020-01-03 00:54:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!