3

I have tested my application on various mobile phones. My applications main functionality is taking pictures and recording video through the phones camera. I didn't face an issue on most of the mobile phones, but I did face this issue on Motorola DROID RAZR. My application works fine when i take a picture. But I'm facing an issue when I record a video. When I record a video, I get a blank screen. There is no preview showing on the mobile screen. I don't why its happening, but on most of the mobile phones its working fine. And taking picture working fine on this phone (the droid razr).

Motorola DROID RAZR configuration,

  1. OPERATING SYSTEM : Android v2.3.5.
  2. CAMERA : HD camera, 8MP.
  3. PROCESSOR : TI OMAP4430

Here is my code,

Camera camera = Camera.open();
Parameters params = camera.getParameters();
camera.setDisplayOrientation(90);
camera.setParameters(params);               
camera.setDisplayOrientation(90);

MediaRecorder recorder = new MediaRecorder();
recorder.setCamera(camera);
recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
recorder.setVideoSize(640, 480);
recorder.setMaxDuration(25000);
recorder.setOrientationHint(90); 

Update:

I have tested this application on Motorola Droid Razr emulator. I got the following exception,

MediaRecorder(430): prepare failed: -17
System.err(430): java.io.IOException: prepare failed.
System.err(430):    at android.media.MediaRecorder._prepare(Native Method)
System.err(430):    at android.media.MediaRecorder.prepare(MediaRecorder.java:590)

But I didn't get this exception on my other emulator. How to resolve this issue?

1

2 Answers 2

3

Finally I found the solution. Below code works well on all devices. ;)

        Holder holder = getHolder();
        holder.addCallback(this);
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        Camera camera = Camera.open();
        try {
            camera.setPreviewDisplay(holder);
            camera.startPreview();
        } catch (IOException e) {
            Log.e(TAG, e.getMessage());
            e.printStackTrace();
        }

        camera.unlock();
        MediaRecorder recorder = new MediaRecorder();
        recorder.setCamera(camera);
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setVideoSize(640, 480);
        recorder.setVideoFrameRate(20);
        recorder.setVideoEncodingBitRate(3000000);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);

        try {

            String videopath = File.createTempFile("video", ".mp4")
                    .getAbsolutePath();

            recorder.setOutputFile(videopath);

        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {           
            e.printStackTrace();
        }

        recorder.setPreviewDisplay(holder.getSurface());
1
  • Absolute life-saver... I was afraid I was going to go bald at 21 from pulling out my hair... Just wish I knew which line was the specific one that actually fixed it though, but so happy regardless
    – Cruceo
    Jun 27, 2012 at 0:01
0

It appears this device does not support MediaRecorder.setOrientationHint(). Try commenting out that line. mMediaRecorder.setOrientationHint(90)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.