如何将视频内的视频旋转90度并使其全屏显示

时间:2015-12-01 12:58:06

标签: android video android-videoview

我正在尝试将视频作为背景播放。但我只能拿它一半的屏幕。因此,我需要将视频拉伸至16:9并将其旋转90度以使其全屏显示。

我现在正在测试项目中工作。

MainActivity

public class MainActivity extends AppCompatActivity implements GestureOverlayView.OnGesturePerformedListener{

GestureLibrary gestureLib;
VideoView vvRick;
private Button btnTest;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

        gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
        if (!gestureLib.load()) {
            finish();
        }
        GestureOverlayView gOverlay =
                (GestureOverlayView) findViewById(R.id.gOverlay);
        gOverlay.addOnGesturePerformedListener(this);

        vvRick = (VideoView)findViewById(R.id.vvRick);
        btnTest = (Button)findViewById(R.id.btnTest);

        btnTest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "Workss!!",
                        Toast.LENGTH_LONG).show();
            }
        });


    }

    public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
        ArrayList<Prediction> predictions = gestureLib.recognize(gesture);

        if (predictions.size() > 0 && predictions.get(0).score > 3.0) {
            String result = predictions.get(0).name;
            if ("turn".equalsIgnoreCase(result)) {
                Toast.makeText(this, "Reverse", Toast.LENGTH_LONG).show();
            } else if ("easteregg".equalsIgnoreCase(result)) {
                Toast.makeText(this, "EasterEgg", Toast.LENGTH_LONG).show();
                vvRick.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.rickroll));
                vvRick.start();
            } else{
                Toast.makeText(this, "FOUT", Toast.LENGTH_LONG).show();

            }
        }
    }
}

布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/rlMain">

<VideoView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/vvRick"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center"
    android:background="@android:color/transparent" />

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/home_container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/transparent">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button Test"
        android:id="@+id/btnTest"
        android:layout_gravity="center" />

</FrameLayout>

<android.gesture.GestureOverlayView
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:id="@+id/gOverlay"
    android:minHeight="200dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:background="@android:color/transparent"></android.gesture.GestureOverlayView>

1 个答案:

答案 0 :(得分:1)

  

即使正确设置了合成矩阵并使用了旋转属性,VideoView也不支持旋转视频。

     

您可以做的是使用TextureView并设置其属性rotation =“90”(例如)。然后它将旋转帧,但宽高比是您需要处理自己的东西。为此,您可以使用textTureView.setScaleX((screenHeight * 1.0f)/ screenWidth)

阅读本文了解更多信息: https://stackoverflow.com/a/16490065/4503373