Swipe Gesture are not working in YouTubePlayerView in full screen mode
Asked Answered
N

2

10

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.

Neilla answered 10/6, 2013 at 19:59 Comment(1)
check this link it might help you #16788444Always
G
1

You can try Extending YoutubePlayerView and Override onTouchEvent and return false

Ghoul answered 28/6, 2014 at 15:2 Comment(1)
Not valid, at least in 2017. Youtube classes are final and you can't override them. I tried to do reverse engineering because the source code is not available and the dependencies make me to try to find other solution.Springwood
S
1

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.

Springwood answered 9/8, 2017 at 15:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.