1

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

这是我的主要功能

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>

它正在工作,但在纵向模式下,surfaceview 没有占用全宽,但它只占用宽度的 1/4 部分,其他 3/4 部分显示黑色

请给我解决方案

谢谢

4

0 回答 0