滑动手势在全屏模式下无法在YouTubePlayerView中使用 [英] Swipe Gesture are not working in YouTubePlayerView in full screen mode
问题描述
我正在使用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.
请帮助我.预先感谢.
推荐答案
迟到总比没有好.
问题等同于CSS中的z-index.全屏视频是在活动开始后添加的,并且在视图堆栈的最顶部,因此所有内容都在其中.
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.
- 等待将视频添加到屏幕.您可以为当前播放器设置
PlayerStateChangeListener
,并在onVideoStarted
回调方法中执行以下代码. -
以下代码将添加一个透明对话框,该对话框将位于视图层次结构的顶部(甚至高于视频):
- 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();
}
});
-
在您的styles.xml中
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>
您还可以设置cancel回调或执行任何操作.由你决定.
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中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!