Camera issue with Motorola DROID RAZR When I recording the video

a 夏天 提交于 2019-12-04 15:43:11

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());

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!