[SOLVED] How to use jMediaRecorder to record video ? lazarus / 43-Android ---------------------------------------------------------------------- hongdusocal · 2023-07-09 22:26 I have tried the jMediaRecorder to record audio. It is really straightforward and convenient. But when I tried to use it for recording video, I cannot SetVideoSource, the app will crash. Can someone please help me use the jMediaRecorder to support video recording? Thanks, Hong ---------------------------------------------------------------------- jmpessoa · 2023-07-10 15:36 Hi, hongdusocal! What about demo "AppMediaRecorderDemo1"?  Is it working? ---------------------------------------------------------------------- hongdusocal · 2023-07-10 16:58 Hi jmpessoa, Thanks again for your quick response. The AppMediaRecorderDemo1 works perfectly well for capturing audio record. But when I tried to capture video, in particular, when I tried to run jMediaRecorder1.SetVideoSource, this line will always crash the phone. I checked the java source code and couldn't find the related SetCamera method that jMediaRecorder needs to capture video. I don't know if MediaRecorder can work on its own to capture video but needs java source code programming, or it can be combined with CustomCamera object to record video. Any support is highly appreciated. Best regards, Hong ---------------------------------------------------------------------- hongdusocal · 2023-07-21 18:16 I struggled for a while and read some information from the internet. I can finally capture video by modifying jCustomcamera.java  and inserting a java MediaRecorder object to do the video recording. Many parameters are hardwired and should be different for different phones. I didn't want to change the CustomCamera component in Lazarus to add functions such as PrepareVideo(filename) and StartVideoRecord(), so I repurposed TakePicture(String _filename) and getImage() to prepare the camera and record the video. The code is as follows. You can modify it for your own purpose. Notice that this is meant for old phones. New phones should use higher camera APIs. public void TakePicture(String _filename) throws IOException {                    if (mRecorder != null)           {mRecorder.stop();            mRecorder.release();            mRecorder=null;           };         if(camera != null)           {//camera.reconnect();            camera.stopPreview();            camera.release();            camera=null;           }         mFileName = _filename;         camera=Camera.open();         if(camera == null) return;         camera.setPreviewDisplay(this.getHolder());         Camera.Parameters parameters=camera.getParameters();         parameters.setPreviewSize(640,480);         camera.setParameters(parameters);         camera.setDisplayOrientation(orientation);         camera.startPreview();         camera.unlock();         mRecorder=new MediaRecorder();         mRecorder.setCamera(camera);         mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);         mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);         mRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);         mRecorder.setMaxDuration(5000);         mRecorder.setVideoSize(640,480);         mRecorder.setVideoFrameRate(30);         mRecorder.setVideoEncodingBitRate(2000000);         mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);//MPEG_4_SP         mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); //        mRecorder.setAudioSamplingRate(16000);         mRecorder.setPreviewDisplay(this.getHolder().getSurface());         mRecorder.setOutputFile(mFileName);         mRecorder.prepare();         //mRecorder.start(); //used getImage to start     }     public Bitmap GetImage() {         if (mRecorder !=null) mRecorder.start();         return mPicture;     }