摄像头2:无法全屏录制视频?

Ste*_*lla 5 android camera-api

我使用Google官方示例使用Camera API 2来处理视频录制.但问题是我无法全屏显示,因为我将屏幕方向仅限于肖像.这是我编辑的xml和官方的xml.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <AutoFitTextureView
        android:id="@+id/texture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <Button
            android:id="@+id/video"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/label_record" />

        <ImageView
            android:id="@+id/info"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|right"
            android:contentDescription="Description"
            android:padding="20dp"
            android:src="@drawable/ic_more" />

    </FrameLayout>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我认为这里是通过纵横比设置视频屏幕大小,TextureView但我无法全屏显示.任何帮助是极大的赞赏.

mVideoSize = chooseVideoSize(map.getOutputSizes(MediaRecorder.class));
mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height, mVideoSize);
int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
    mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());
} else {
    mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth());
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Ano*_*p M 2

您需要处理预览尺寸来控制录制的屏幕尺寸。使用相同的chooseVideoSize方法通过获取类的输出大小来使预览全屏SurfaceTexture

private static Size chooseVideoSize(Size[] choices) {
        for (Size size : choices) {
            if (size.getWidth() == size.getHeight() * 4 / 3 && size.getWidth() <= 1080) {
                return size;
            }
        }
        Log.e(TAG, "Couldn't find any suitable video size");
        return choices[choices.length - 1];
    }
Run Code Online (Sandbox Code Playgroud)

那是

  mPreviewSize = chooseVideoSize(map.getOutputSizes(SurfaceTexture.class));
Run Code Online (Sandbox Code Playgroud)