问题
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.
- Wait for the video to be added to the screen. You can set a
PlayerStateChangeListener
to your current player and execute the following code inonVideoStarted
callback method. 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(); } });
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