Java Question Record Video

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hey,

I'm using my current Advanced Camera Library to add a Video Recorder to it.

This is my Java code:

B4X:
MediaRecorder m_recorder = new MediaRecorder();

   /**
    * Initialize the video recorder. Filename as string Duration as integer,
    * Width as integer, Height as integer, FrameRate as integer. Files are
    * saved on sdcard as Filename.mp4
    */
   public void initRecorder(String Filename, int Duration, int Width,
         int Height, int FrameRate) throws IOException {
      ;
      m_recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      m_recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
      m_recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
      m_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      m_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
      m_recorder.setOutputFile("/sdcard/" + Filename);
      m_recorder.setVideoSize(Width, Height);
      m_recorder.setVideoFrameRate(FrameRate);
      m_recorder.setPreviewDisplay(sv.getHolder().getSurface());
      m_recorder.prepare();

   }

   /**
    * starts the video recorder.
    * 
    */
   public void startRecorder() {

      isRecording = true;
      try {
         m_recorder.start();

      } catch (IllegalStateException e) {
         e.printStackTrace();
      }
   }


But when executing the code, I get a java.lang.runtimeexception: start failed
Log:


I respected all guidelines from the MediaRecorder and I still don't see why it doesn't work.
 

agraham

Expert
Licensed User
Longtime User
I think you need to invoke MediaRecorder.setCamera with an unlocked Camera object before calling the other MediaRecorder methods. The MediRecorder API seems to be confusingly coded and appallingly documented.

You may need to set "m_recorder.setVideoSource( MediaRecorder.VideoSource.CAMERA );"
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…