相机不支持setVideoSize()

时间:2013-06-02 17:38:33

标签: android android-camera

我尝试录制视频并播放

我注意到许多设备在开始录制视频时都会瘫痪。

来自logcat的

我意识到问题是视频的大小。

相机视图很小,几个像素,这是问题吗?

我需要修理什么?怎么样?

private boolean prepareVideoRecorder() {

        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)
        mMediaRecorder.setProfile(CamcorderProfile
                .get(CamcorderProfile.QUALITY_HIGH));

        // Step 4: Set output file
        mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO)
                .toString());
        outputFileName = getOutputMediaFile(MEDIA_TYPE_VIDEO).toString();
        Log.d(TAG,"idan outputFileName" + outputFileName);


        // Step 5: Set the preview output
        // mMediaRecorder.setVideoSize(640, 480); //try
        mMediaRecorder.setPreviewDisplay(mPreview.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 surfaceCreated(SurfaceHolder holder) {
        // The Surface has been created, now tell the camera where to draw the preview.





     Log.d(TAG,"surfaceCreated camera id" + mCamera );

     try {
            CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
            Camera.Parameters parameters = mCamera.getParameters();
            parameters.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight);
            mCamera.setParameters(parameters);
            mCamera.setPreviewDisplay(holder);
            mCamera.startPreview();
        }
        catch (IOException e) {
            Log.d(TAG, "Error setting camera preview: " + e.getMessage());
        }
}

logcat错误:

06-02 19:29:14.177: D/CameraSource(115): Camera does not support setVideoSize()
06-02 19:29:14.177: D/CameraSource(115): Requested video size (1920x1088) isSetVideoSizeSupportedByCamera 0
06-02 19:29:14.177: E/CameraSource(115): Video dimension (1920x1088) is unsupported
06-02 19:29:14.177: D/CameraService(115): unlock (pid 115)
06-02 19:29:14.177: D/QualcommCameraHardwareZSL(115): virtual bool android::QualcommCameraHardware::recordingEnabled() recordingState=0
06-02 19:29:14.177: D/CameraService(115): clear mCameraClient (pid 115)
06-02 19:29:14.177: E/MediaRecorder(30873): start failed: -19
06-02 19:29:14.177: V/MediaRecorderJNI(30873): process_media_recorder_call
06-02 19:29:14.177: E/MediaRecorder(30873): start failed.
06-02 19:29:14.177: E/MediaRecorder(30873): try to delete broken file: /mnt/sdcard/Movies/Your_voice/Your_voice020613_192914.mp4
06-02 19:29:14.187: D/AndroidRuntime(30873): Shutting down VM
06-02 19:29:14.187: W/dalvikvm(30873): threadid=1: thread exiting with uncaught exception (group=0x40ac3228)
06-02 19:29:14.187: E/AndroidRuntime(30873): FATAL EXCEPTION: main
06-02 19:29:14.187: E/AndroidRuntime(30873): java.lang.RuntimeException: start failed.
06-02 19:29:14.187: E/AndroidRuntime(30873):    at android.media.MediaRecorder._start(Native Method)
06-02 19:29:14.187: E/AndroidRuntime(30873):    at android.media.MediaRecorder.start(MediaRecorder.java:712)
06-02 19:29:14.187: E/AndroidRuntime(30873):    at com.example.uploadvideo.MainActivity.onPlaying(MainActivity.java:165)

2 个答案:

答案 0 :(得分:2)

CamcorderProfile.get(int)返回默认(后方)摄像头的配置文件。如果您的mCamera是前置摄像头,则应使用CamcorderProfile.get(int, int)和相应的cameraId。

答案 1 :(得分:0)

/ **获取Camera对象实例的安全方法。 * /

public Camera getCameraInstance () {
    Camera c = null;
    try {
        c = Camera.open(Camera.getNumberOfCameras() - 1);
    } catch (Exception e) {
        e.printStackTrace();
        onError();
    }
    return c;
}