Motorola DROID RAZR Camera Problem When I Record Video

I have tested my application on different mobile phones. My main function of apps is to take pictures and record videos through my phone camera. I have not encountered the problem on most mobile phones, but I have encountered this problem on the Motorola DROID RAZR . My app works great when I take a picture. But I ran into a problem when I record a video. When I record a video, I get a blank screen. There is no preview on the mobile screen. I don't understand why this is happening, but it works fine on most mobile phones. And photography works great on this phone (droid size).

Motorola DROID RAZR configuration,

  • OPERATING SYSTEM: Android v2.3.5.
  • CAMERA: HD camera, 8 MP.
  • 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 tested this app 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 another emulator. How to solve this problem?

+3


source to share


2 answers


Finally I found a 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());

      

+3


source


It looks like this device doesn't support MediaRecorder.setOrientationHint (). Try commenting out this line. mMediaRecorder.setOrientationHint (90)



0


source







All Articles