Swipe Gesture are not working in YouTubePlayerView in full screen mode

▼魔方 西西 提交于 2019-12-01 14:34:06

问题


I am using the YouTube API, and I want to apply the Swipe left and right gesture on YouTubePlayerView in full screen mode.

The Swipe gestures are not working in Android version 4.0+ when YouTubePlayerView is in full screen mode.

Please help me with this. Thanks in advance.


回答1:


You can try Extending YoutubePlayerView and Override onTouchEvent and return false




回答2:


Better late than never.

The problem is the equivalent to the z-index in css. The video in fullscreen is added after the activity is started and on the most top of the view stack so everything is under it.

In this example, we are going to put a fullscreen-invisible dialog above everything so that we can attach any gesture we want to its view (layout) and execute callbacks in our activity.

  1. Wait for the video to be added to the screen. You can set a PlayerStateChangeListener to your current player and execute the following code in onVideoStarted callback method.
  2. The following code will add a transparent dialog which will be on top of the view hierarchy (even upper than the video):

    // Add listeners to YouTubePlayer instance
    player.setPlayerStateChangeListener(new PlayerStateChangeListener() {
       //... other methods 
         @Override
         public void onVideoStarted() {      
    
            // Setting style with no title (defined later in the answer)
            BasicPlayerActivity.this.mDialog = new Dialog(BasicPlayerActivity.this, R.style.AppTheme_NoActionBar_Fullscreen);     BasicPlayerActivity.this.mDialog.setContentView(R.layout.overlay_layout);
            View v = BasicPlayerActivity.this.mDialog.findViewById(R.id.container);
    
            //Adding touch listener (OR ANY LISTENER YOU WANT)  
            v.setOnTouchListener(new OnSwipeTouchListener(BasicPlayerActivity.this){        
                public void onSwipeRight() {
                    // TODO: Previous Video or whatever
                }
    
                public void onSwipeLeft() {
                    // TODO: Next video or whatever
                }
            });
    
            //Setting transparent dialog background (invisible)                                                                       
            BasicPlayerActivity.this.mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
            BasicPlayerActivity.this.mDialog.show();
    }
    });
    
    1. In you styles.xml

          <style name="AppTheme.NoActionBar">
              <item name="windowActionBar">false</item>
              <item name="windowNoTitle">true</item>
          </style>
      
          <style name="AppTheme.NoActionBar.Fullscreen">
              <item name="android:windowFullscreen">true</item>
              <item name="android:backgroundDimEnabled">false</item>
              <item name="android:backgroundDimAmount">0</item>
          </style>
      

You can also set the cancel callback or whatever to do things. It is up to you.

I hope this would help to you or anyone having this problem.



来源:https://stackoverflow.com/questions/17031817/swipe-gesture-are-not-working-in-youtubeplayerview-in-full-screen-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!