Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8767627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:51:50+00:00 2026-06-13T16:51:50+00:00

I’m trying to develop an App that amongst other things can record videos from

  • 0

I’m trying to develop an App that amongst other things can record videos from its User. So I need to capture the video with the front facing camera if there is one.
I build a camera preview and this works fine.
I used the Android How-To Sites to build a MediaRecorder and set it up.
If I use a CamcorderProfile my Media Server dies when I call start().
If I set up the encoder by myself the media server throws a runtime exception at start() with the message “start failed: -19”
I found some questions about this topic here but none solved my problem.
I think that this could be related to the fact that I’m not using the back-facing camera. Maybe I didn’t found the right documentary to build the proper code. I think this isn’t only my problem and I would be happy to get some more knowledge about the camera usage.
My Code follows:

the onResume() where the preview is set up

protected void onResume() {
        super.onResume();
        // 1. set up camera preview
        if(checkCameraHardware(this)){
            mCamera = getCameraInstance();
            mCameraPreview = new CameraPreview(this, mCamera);
            FrameLayout preview = (FrameLayout) findViewById(id.cameraPreview);
            preview.addView(mCameraPreview);
        }
        else{
            Log.d("Recorder", "camera check returned false");
        }
}

the used method checkCameraHardware()

private boolean checkCameraHardware(Context context){
    boolean ret = true;
    if(context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){
            ret = true;
    }
    else {
        ret = false;
        }
    return ret;
}

and the method getCameraInstance()

public static Camera getCameraInstance(){
    Camera c = null;
    int cnum = 0;
    mCamSelect = 0;
    Camera.CameraInfo caminfo = new CameraInfo();
    try {
        cnum = Camera.getNumberOfCameras();
        Log.d("getCameraInstance", String.valueOf(cnum));
        for(int i = 0;i<cnum;i++){
            Camera.getCameraInfo(i, caminfo);
            if(caminfo.facing == CameraInfo.CAMERA_FACING_FRONT){
                mCamSelect = i;
                break;
            }
        }
        c = Camera.open(mCamSelect); // attempt to get a Camera instance
    }
    catch (Exception e){
        Log.d("getCameraInstance", "FATAL camera could not be opened");
        // Camera is not available (in use or does not exist)
    }
    if(c==null)Log.d("getCameraInstance", "no camera returned");
    return c; // returns null if camera is unavailable
}

this code snippet shows where the error appears ( inside a onClick Callback )

if(prepareVideoRecorder()){
    mMediaRecorder.start(); //here the errors occure
    recording = true;
    //start recording
}

and the three MediaRecorder related methods: prepareVideoRecorder(), releaseMediaRecorder() and release Camera()

private void releaseMediaRecorder(){
        if (mMediaRecorder != null) {
            mMediaRecorder.reset();   // clear recorder configuration
            mMediaRecorder.release(); // release the recorder object
            mMediaRecorder = null;
            mCamera.lock();           // lock camera for later use
        }
    }

private void releaseCamera(){
    if (mCamera != null){
        mCamera.release();        // release the camera for other applications
        mCamera = null;
    }
}

private boolean prepareVideoRecorder(){

    //ex: mCamera = getCameraInstance();
    mMediaRecorder = new MediaRecorder();

    // Step 1: Unlock and set camera to MediaRecorder
    mCamera.unlock();
    mMediaRecorder.setCamera(mCamera);

    // Step 2: Set sources
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)


    CamcorderProfile profile = CamcorderProfile.get(mCamSelect, CamcorderProfile.QUALITY_HIGH);
    if(profile == null){Log.d(tag, "the camcorder profile instance is null");

        mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
    }else{
        mMediaRecorder.setProfile(profile);
    }



    // Step 4: Set output file
    //ex: mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());
    mMediaRecorder.setOutputFile(currentVidFile.getAbsolutePath());

    // Step 5: Set the preview output
    mMediaRecorder.setPreviewDisplay(mSlideview.getHolder().getSurface());

    // Step 6: Prepare configured MediaRecorder
    try {
        mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
        Log.d(tag, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    } catch (IOException e) {
        Log.d(tag, "IOException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    }
    return true;
}

public void onGesturePerformed(GestureOverlayView arg0, Gesture arg1) {
    // TODO Auto-generated method stub

}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:51:51+00:00Added an answer on June 13, 2026 at 4:51 pm

    I’m answering my own question to help everybody who has the same problem.
    The error was so stupid that it’s a little embarrassing to admit it.

    On preparing the audio and video sources I committed the wrong surface.

    I have different SurfaceViews and committed the surface of the wrong SurfaceView to the MediaRecorder. This resulted in the attempt to connect two different sources to the surface what is not possible and leads to a shutdown of the Media Server.

    I tested my App on a GalaxyPad 10.1 and the video recording works fine.
    I tested the App on the Dalvik VM and the Video is black/white but also works.

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I need to clean up various Word 'smart' characters in user input, including but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.