Note that there are some explanatory texts on larger screens.

plurals
  1. POsetMaxDuration failed when creating Android video recoder
    text
    copied!<p>I'm currently trying to create a very simple video recorder on Android without using intent, just a custom app. My code snippet is following</p> <p><pre> import java.io.IOException;</p> <p>import android.app.Activity; import android.media.MediaRecorder; import android.net.NetworkInfo; import android.os.Bundle; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView;</p> <p>public class CameraActivity extends Activity implements SurfaceHolder.Callback { public enum State { UNKNOWN, CONNECTED, NOT_CONNECTED }</p> <code>SurfaceView cameraView; SurfaceHolder holder; public boolean mListening; public Object mState; public NetworkInfo mNetworkInfo; public boolean mSending; boolean recording = false; public static final String TAG = "VIDEOCAPTURE"; private MediaRecorder recorder; protected void captureVideo() { if (recording) { recorder.stop(); // recorder.release(); recording = false; Log.v(TAG, "Recording Stopped"); // Let's initRecorder so we can record again initRecorder(); prepareRecorder(); } else { recording = true; recorder.start(); Log.v(TAG, "Recording Started"); } } private void initRecorder() { recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); recorder.setOutputFile("/sdcard/videocapture_example.mp4"); recorder.setMaxDuration(50000); // 50 seconds recorder.setMaxFileSize(5000000); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); recorder = new MediaRecorder(); initRecorder(); setContentView(R.layout.main); cameraView = (SurfaceView) this.findViewById(R.id.CameraView); holder = cameraView.getHolder(); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); holder.addCallback(this); } private void prepareRecorder() { recorder.setPreviewDisplay(holder.getSurface()); try { recorder.prepare(); } catch (IllegalStateException e) { e.printStackTrace(); finish(); } catch (IOException e) { e.printStackTrace(); finish(); } } @Override public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { } @Override public void surfaceCreated(SurfaceHolder holder) { Log.v(TAG, "surfaceCreated"); prepareRecorder(); } @Override public void surfaceDestroyed(SurfaceHolder holder) { // camera.stopPreview(); // camera.release(); Log.v(TAG, "surfaceDestroyed"); if (recording) { recorder.stop(); recording = false; } recorder.release(); finish(); } </code></pre> <p>} </p> <p>But when i deployed this code within emulator, in the LogCat i got some errors like this.</p> <p>java.lang.RuntimeException: Unable to start activity ComponentInfo...</p> <p>java.lang.RuntimeException: setMaxDuration failed. at android.media.MediaRecorder.setMaxDuration(Native Method)</p> <p>What wrong with my code?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload