DaaarK
DaaarK

Reputation: 1

Mediarecorder start failed 19

my code working android 2.33 but android 4.11 catching error mediarecorder start failed 19 in mediarecorder.start() line why this i don't understand

8-17 18:07:57.468  11453-11453/com.example.SelfVideocaptureTest E/MediaRecorderJNI﹕ Application lost the surface
08-17 18:08:24.577      89-3117/? E/CameraSource﹕ Camera connection could not be established.
08-17 18:08:24.577  11453-11453/com.example.SelfVideocaptureTest E/MediaRecorder﹕ start failed: -19
08-17 18:08:24.581  11453-11453/com.example.SelfVideocaptureTest E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: start failed.
            at android.media.MediaRecorder.start(Native Method)
            at com.example.SelfVideocaptureTest.MyActivity.onClick(MyActivity.java:146)
            at android.view.View.performClick(View.java:4084)
            at android.view.View$PerformClick.run(View.java:16966)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)

Who can help me ??? It's my code

private boolean prepareVideoRecorder() {

            mediaRecorder = new MediaRecorder();

            if (Build.VERSION.SDK_INT < 14)
                    camera.unlock();
            mediaRecorder.setCamera(camera);
            mediaRecorder.setPreviewDisplay(preView.getHolder().getSurface());
            mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
            mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

            mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));
            mediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).getAbsolutePath());
            mediaRecorder.setPreviewDisplay(preView.getHolder().getSurface());
            try
                {
                    mediaRecorder.prepare();
                } catch (IOException e)
                {
                    e.printStackTrace();
                    releaseMediaRecorder();
                    return false;
                }
            return true;
        }

    @Override
    public void onClick(View view)
        {
            if (isRecording)
                {
                    mediaRecorder.stop();
                    releaseMediaRecorder();
                    if (Build.VERSION.SDK_INT < 14)
                        camera.lock();
                    button.setText("Capture");
                    isRecording = false;
                } else if (prepareVideoRecorder())
                {
                    mediaRecorder.start();
                    button.setText("Stop");
                    isRecording = true;
                } else
                {
                    releaseMediaRecorder();
                    Toast.makeText(getBaseContext(), "cannot record", 0).show();
                }
        }

I saw these pages

Upvotes: 0

Views: 1864

Answers (2)

Dave Thomas
Dave Thomas

Reputation: 3827

I was also having the same issue and looked at all of those answers too =(. Tried a million things... and different ways of setting up MediaRecorder.

I just got it working and it was because I wasn't calling ->

android.hardware.Camera.unlock()

Read capturing videos section at top: https://developer.android.com/guide/topics/media/camera.html

I notice you are calling unlock as well but only for version lower than 14? Perhaps it needs to be called for all versions?

Upvotes: 2

Tash Pemhiwa
Tash Pemhiwa

Reputation: 7685

From the research I have done, error code -19 comes about when there is a problem with the size of the video as set by MediaRecorder#setVideoSize()

Upvotes: 0

Related Questions