【问题标题】:Full screen Videoview doesn't hide menu bar during rotation全屏 Videoview 在旋转期间不隐藏菜单栏
【发布时间】:2017-07-18 13:58:22
【问题描述】:

我正在开发一个 youtube/rtmp 实时视频应用程序,使用 videoview 和来自网络各地的示例代码,所以秋天我的应用程序可以工作,但是当我改变方向时,我遇到了一个问题,实时视频旋转和扩展很好但它不会完全全屏,我如何设置只有在进入横向模式时才能完全全屏?

我的主要活动。

    progressdialog = ProgressDialog.show(this, "", " Cargando vídeo por favor espere...", true);
    progressdialog.setCancelable(true);

    final VideoView vidView = (VideoView)findViewById(R.id.video_view);
    String vidAddress = "http://videourl/playlist.m3u8";
    Uri vidUri = Uri.parse(vidAddress);

    vidView.setVideoURI(vidUri); 

    MediaController vidControl = new MediaController(this);
    vidControl.setAnchorView(vidView);
    vidView.setMediaController(vidControl);

    vidView.setOnPreparedListener(new OnPreparedListener() {

        public void onPrepared(MediaPlayer arg0) {
            progressdialog.dismiss();
           vidView.start();


        }
    });

主xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" >

<GridView
    android:id="@+id/list_playlist"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/video_view"
    android:layout_margin="5sp"
    android:gravity="center"
    android:numColumns="2"
    android:scrollbars="none" >

</GridView>

<RelativeLayout
    android:id="@+id/layout_ad"
    android:layout_width="match_parent"
    android:layout_height="50sp"
    android:layout_alignParentBottom="true"
    android:gravity="center_horizontal" >
</RelativeLayout>

<VideoView
    android:id="@+id/video_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"/>

【问题讨论】:

    标签: java android eclipse android-videoview


    【解决方案1】:

    在您的OrientationChange 事件或任何将视频发送到fullscreen 的事件中,您必须隐藏 Status BarAction Bar。这样,当您更改方向时,状态栏和操作栏将被隐藏,允许视频全屏播放。

    如何隐藏状态栏:

    1. See this from Android Developer

    如何隐藏操作栏:

    2. See This Post

    希望这对您有所帮助。

    【讨论】:

      【解决方案2】:

      我已经设法通过应用以下代码解决了这个问题,但仍然不会进入完整的全屏。

      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
              this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
              this.requestWindowFeature(Window.FEATURE_NO_TITLE);
      
          }
      
          setContentView(R.layout.activity_main);
      

      【讨论】:

        【解决方案3】:

        在 onConfigurationChanged 中像这样为视频帧设置规则

        @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);
        if (newConfig.orientation == ORIENTATION_LANDSCAPE){
        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) rel.getLayoutParams();
                lp.addRule(RelativeLayout.ALIGN_PARENT_TOP, R.id.relativeFrame);
                lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, R.id.relativeFrame);
                lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, R.id.relativeFrame);
                lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, R.id.relativeFrame);
                rel.setLayoutParams(lp);
        
                View decorView = getWindow().getDecorView();
                int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
                decorView.setSystemUiVisibility(uiOptions);
        }
        

        记得在配置变回prtrait时删除规则

        if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        
        
                RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) rel.getLayoutParams();
                lp.removeRule(RelativeLayout.ALIGN_PARENT_TOP);
                lp.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                lp.removeRule(RelativeLayout.ALIGN_PARENT_LEFT);
                lp.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                rel.setLayoutParams(lp);
                View decorView = getWindow().getDecorView();
                int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
                decorView.setSystemUiVisibility(uiOptions);
            }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-04-30
          • 1970-01-01
          • 1970-01-01
          • 2012-01-12
          相关资源
          最近更新 更多