Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid video record error
    text
    copied!<p>Can anybody point out the error I am doing? I am trying to record a short video, but somehow it finds a way to crash.</p> <p><strong>Source Code:</strong></p> <pre><code>public class Start_recording extends Activity implements SurfaceHolder.Callback { MediaRecorder recorder; SurfaceHolder surfaceHolder; SurfaceView myVideoView; Camera camera; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); camera = Camera.open(); camera.unlock(); recorder = new MediaRecorder(); setContentView(R.layout.activity_main_rst); myVideoView = (SurfaceView)findViewById(R.id.surface_camera); surfaceHolder = myVideoView.getHolder(); surfaceHolder.addCallback(this); initMediaRecorder(); boolean exists = (new File(android.os.Environment.getExternalStorageDirectory() + "/Record/")).exists(); if (!exists) { new File(android.os.Environment.getExternalStorageDirectory() + "/Record/").mkdirs(); } try { recorder.prepare(); // This is the line of error. recorder.start(); Thread.sleep(36000); recorder.stop(); setupActionBar(); } catch(Exception e) { Log.v("Error is there : ",e.toString()); e.printStackTrace(); } } public void initMediaRecorder() { try { recorder.setPreviewDisplay(surfaceHolder.getSurface()); recorder.setCamera(camera); recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(android.os.Environment.getExternalStorageDirectory()+"/Record/test.3gp"); recorder.setMaxDuration(300000); } catch(Exception f) { Log.v("Exception here : ",f.toString()); f.printStackTrace(); } } } </code></pre> <p>Error :</p> <pre><code>E/MediaRecorderJNI(1575): Application lost the surface V/Error is there :(1575): java.io.IOException: invalid preview surface W/System.err(1575): java.io.IOException: invalid preview surface W/System.err(1575): at android.media.MediaRecorder._prepare(Native Method) W/System.err(1575): at android.media.MediaRecorder.prepare(MediaRecorder.java:666) W/System.err(1575): at com.example.project.Start_recording.onCreate(Start_recording.java:51) </code></pre> <p>I have added the permissions correctly in the Manifest file and also set the setPreviewDisplay(). But I get as invalid preview surface.Please correct me.</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