方向更改时,视频不会重新调整大小

时间:2022-07-29 21:26:35

I have a video displayed using SurfaceView in a fragment. If I change the orientation of the screen while the video is playing it doesn't resize. For example, if the video is playing in landscape size (full screen), it doesn't go to portrait size when the screen is rotated. It remains if landscape size. If I start the video in landscape, it won't change to portrait.I am using the following in my manifest:

我在片段中使用SurfaceView显示视频。如果我在播放视频时更改屏幕方向,则不会调整大小。例如,如果视频以横向大小(全屏)播放,则在旋转屏幕时它不会变为纵向大小。如果景观大小仍然存在。如果我以横向方式启动视频,它将不会更改为纵向。我在清单中使用以下内容:

    <activity
        android:name=".BassActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        >

I have this in my "onCreate"

我在“onCreate”中有这个

 @Override
 public void onCreate(Bundle savedInstanceState) {
   if (VERBOSE) Log.v(TAG, "+++ onCreate +++");
     super.onCreate(savedInstanceState);        
     getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
     setRetainInstance(true);

I would like for the video to re-size, for example from portrait to landscape when I rotate the screen, while it is playing.

我希望视频能够重新调整大小,例如在我旋转屏幕的同时从纵向到横向进行播放。

I also added a toast message to onSurfaceChanged to see when it is triggered,but it is not trigger when I rotate the screen. How can I re-size the video after it has started playing?

我还向onSurfaceChanged添加了一个toast消息,以查看它何时被触发,但是当我旋转屏幕时它不会触发。如何在视频开始播放后重新调整大小?

1 个解决方案

#1


2  

use this config changes

使用此配置更改

if android:configchanges = "orientation"

如果android:configchanges =“orientation”

public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // Checks the orientation of the screen
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
            // for example the width of a layout  
            int width = 300;
            int height = LayoutParams.WRAP_CONTENT;
            WebView childLayout = (WebView) findViewById(R.id.webview);
            childLayout.setLayoutParams(new LayoutParams(width, height));
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
        }
    }

#1


2  

use this config changes

使用此配置更改

if android:configchanges = "orientation"

如果android:configchanges =“orientation”

public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // Checks the orientation of the screen
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
            // for example the width of a layout  
            int width = 300;
            int height = LayoutParams.WRAP_CONTENT;
            WebView childLayout = (WebView) findViewById(R.id.webview);
            childLayout.setLayoutParams(new LayoutParams(width, height));
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
        }
    }