Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture video in Android?

Tags:

I would like to create a video recorder and so far haven't figured out how to set parameters in order to successfully go through MediaRecorder.prepare() method.

Executing the following method

public void start() throws IOException{     String state = android.os.Environment.getExternalStorageState();     if(!state.equals(Environment.MEDIA_MOUNTED))     {         throw new IOException("SD card is not mounted. It is " + state + ".");     }     File directory = new File(path).getParentFile();     if(!directory.exists() && !directory.mkdirs())     {         throw new IOException("Path to file could not be created.");     }      recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);     recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);     recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);     recorder.setVideoFrameRate(15);     recorder.setVideoSize(176, 144);     recorder.setOutputFile(path);     recorder.prepare();     recorder.start();     this.state = VideoRecorderState.STATE_RECORDING; } 

it throws an exception on line recorder.prepare().

How to set parameters in order to be able to capture video?

like image 825
Niko Gamulin Avatar asked Jun 23 '09 14:06

Niko Gamulin


People also ask

How can I capture video from my screen?

Click the Start Recording button or use the Win + Alt + R keyboard shortcut to capture your screen activity. Now perform whatever screen actions you want to capture.

Does Android have screen recording?

The latest Android devices (Android 10 and up) have a built-in screen recorder. If you have an older device, you will need to use a third-party app to screen record, which we'll discuss later. Recording the screen on your newer Android device gives you the option to record your screen with or without sound.


1 Answers

Here is a snippet that works:

m_recorder = new MediaRecorder(); m_recorder.setPreviewDisplay(m_BeMeSurface); 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.setMaxDuration((int) MAX_TIME);  m_recorder.setOnInfoListener(m_BeMeSelf); m_recorder.setVideoSize(320, 240);  m_recorder.setVideoFrameRate(15);  m_recorder.setOutputFile(m_path);  m_recorder.prepare(); m_recorder.start(); 

THE most important thing is the surface. You don't have it, so without it it fails.

Regards

BeMeCollective

like image 78
BeMeCollective Avatar answered Oct 27 '22 01:10

BeMeCollective