在纵向模式android中相机无法正常显示

时间:2013-10-02 18:12:27

标签: android

我正在开发一个应用程序,我必须以纵向模式录制视频我正在使用此代码以纵向录制视频

以下是我的主要功能

SurfaceView srfRecord = (SurfaceView) findViewById(R.id.surfaceRecord);
 surfaceHolder = srfRecord.getHolder();
 surfaceHolder.addCallback(this);
 surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_NORMAL);



public void startRecording(int Request) {



        try {
            srfRecord.setBackgroundColor(Color.TRANSPARENT);
            requestcode = Request;
            sdCardRecordingPath = Environment.getExternalStorageDirectory()
                    + "/" + Request + "_Video.mp4";

            mediaRecorder = new MediaRecorder();
            mCamera.unlock();
            mediaRecorder.setCamera(mCamera);

            mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
            mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
            mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);

            mediaRecorder.setProfile(CamcorderProfile
                    .get(CamcorderProfile.QUALITY_HIGH));
            mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
            mediaRecorder.setOutputFile(sdCardRecordingPath);
            mediaRecorder.setMaxDuration(10000);

            mediaRecorder.prepare();
            mediaRecorder.start();

            mediaRecorder.setOnInfoListener(this);
            mediaRecorder.setOnErrorListener(this);

            recording = true;

        } catch (Exception e) {
            String message = e.getMessage();
            Log.i(null, "Problem Start" + message);
            mediaRecorder.release();
        }

    }

@Override
    public void surfaceCreated(SurfaceHolder holder) {
        mCamera = Camera.open();
        if (mCamera != null) {
            //mCamera.setDisplayOrientation(90);
            Parameters params = mCamera.getParameters();
            params.set("orientation", "portrait");
            mCamera.setDisplayOrientation(90);
            //params.setPreviewSize(screenWidth, screenHeight-180);

            mCamera.setParameters(params);
        } else {
            Toast.makeText(getApplicationContext(), "Camera not available!",
                    Toast.LENGTH_LONG).show();

        }

    }

public void stopRecording() {
        if (mediaRecorder != null) {
            mediaRecorder.setOnInfoListener(null);
            mediaRecorder.setOnErrorListener(null);
            mediaRecorder.stop();
            mediaRecorder.release();
            mCamera.stopPreview();
            mediaRecorder = null;
            recording = false;


        }
    }

布局

<LinearLayout
    android:id="@+id/lnrTop"
    android:layout_width="fill_parent"
    android:layout_height="100dp"
    android:baselineAligned="false"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/lnrPick1"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/custom_backgroud"
        android:orientation="horizontal" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lnrPick2"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="3dp"
        android:layout_weight="1"
        android:background="@drawable/custom_backgroud"
        android:orientation="horizontal" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lnrPick3"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="3dp"
        android:layout_weight="1"
        android:background="@drawable/custom_backgroud"
        android:orientation="horizontal" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lnrPick4"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="3dp"
        android:layout_weight="1"
        android:background="@drawable/custom_backgroud"
        android:orientation="horizontal" >
    </LinearLayout>
</LinearLayout>

<FrameLayout
    android:id="@+id/frmView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/lnrBottom"
    android:layout_below="@+id/lnrTop"
    android:background="@drawable/custom_backgroud" >

    <SurfaceView
        android:id="@+id/surfaceRecord"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="visible" />
    <!-- <TextView -->
    <!-- android:id="@+id/txtTimer" -->
    <!-- android:layout_width="wrap_content" -->
    <!-- android:layout_height="wrap_content" -->
    <!-- android:text="10:00" -->
    <!-- android:textSize="18sp" -->
    <!-- android:textColor="#ffffff"/> -->

    <VideoView
        android:id="@+id/videoview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="gone"
       >
    </VideoView>

    <Chronometer
        android:id="@+id/txtTimer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:format="@string/chronometer_initial_format"
        android:textColor="#ffffff"
        android:textSize="19sp"
        android:textStyle="normal"
        android:typeface="sans" />
</FrameLayout>

<RelativeLayout
    android:id="@+id/lnrBottom"
    android:layout_width="fill_parent"
    android:layout_height="80dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:background="@drawable/custom_backgroud" >

    <Button
        android:id="@+id/btnSettings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:background="@android:drawable/ic_media_play" />

    <Button
        android:id="@+id/btnPlay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@android:drawable/ic_media_play" />

    <Button
        android:id="@+id/btnRefresh"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="10dp"
        android:background="@android:drawable/ic_media_play" />
</RelativeLayout>

它正在工作但是处于纵向模式 表面视图没有占据全宽,但其仅占宽度的1/4而另外3/4部分呈现黑色

请给我解决方案

由于

0 个答案:

没有答案