在全屏模式下,滑动手势在 YouTubePlayerView 中不起作用

Swipe Gesture are not working in YouTubePlayerView in full screen mode(在全屏模式下,滑动手势在 YouTubePlayerView 中不起作用)

本文介绍了在全屏模式下,滑动手势在 YouTubePlayerView 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 YouTube API,我想以全屏模式在 YouTubePlayerView 上应用 Swipe 左右手势.

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

YouTubePlayerView 处于全屏模式时,Swipe 手势在 Android 版本 4.0+ 中不起作用.

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.

推荐答案

迟到总比不到好.

问题相当于css中的z-index.全屏视频是在 Activity 启动后添加的,位于视图堆栈的最顶部,因此所有内容都在其下方.

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. 等待视频添加到屏幕上.您可以为当前播放器设置一个 PlayerStateChangeListener 并在 onVideoStarted 回调方法中执行以下代码.
  2. 以下代码将添加一个透明对话框,该对话框将位于视图层次结构的顶部(甚至高于视频):

  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. 在你的styles.xml中

  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.

这篇关于在全屏模式下,滑动手势在 YouTubePlayerView 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在全屏模式下,滑动手势在 YouTubePlayerView 中不起作用

基础教程推荐