3

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:

Pasha
  • 2,407
  • 18
  • 25
Shekhar
  • 1,767
  • 3
  • 16
  • 19

1 Answers1

19

You should call setAudioEncoder() after setOutputFormat().

IoaN Bah
  • 191
  • 3