【问题标题】:landscape support of video using video view in android在android中使用视频视图对视频的横向支持
【发布时间】:2025-12-16 03:10:01
【问题描述】:

我无法在横向模式下更改视频的方向。这是我的代码:

VideoView videoView = (VideoView) findViewById(R.id.video_view);
    MediaController mediaController = new MediaController(this); //Creating the media controller
    mediaController.setAnchorView(videoView);

    //Specify the location of media file
    Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"
            + R.raw.my_video);

    videoView.setMediaController(mediaController);
    videoView.setVideoURI(uri);
    videoView.requestFocus();
    videoView.start();

    videoView.setOnCompletionListener(this);

在清单中我添加了以下几行:

android:configChanges="keyboard|orientation|screenSize"
        android:screenOrientation="landscape"

这样就不行了。提前致谢!! :)

【问题讨论】:

    标签: android video orientation android-videoview landscape


    【解决方案1】:

    我通过在活动的 onStart 中添加以下代码行解决了这个问题:

    @Override
    protected void onStart() {
        super.onStart();
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
    

    【讨论】:

      【解决方案2】:

      这是我强制将视频缩放为横向的方法,希望对您有所帮助。

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent">
      
          <VideoView
              android:id="@+id/video_view"
              android:layout_alignParentTop="true"
              android:layout_alignParentBottom="true"
              android:layout_alignParentLeft="true"
              android:layout_alignParentRight="true"
              android:layout_width="match_parent"
              android:layout_height="match_parent"/>
      
      </RelativeLayout>
      

      【讨论】:

        【解决方案3】:

        可以通过更改屏幕方向来更改视频视图的方向。

        使用this 在按下按钮等时动态更改设备的方向。

        您可以按照自己的方式定义一个新的layout-landscape。所以基本上每当你按下按钮时,设备的方向都会改变,因此也会改变视频视图的方向。

        【讨论】:

          最近更新 更多