Swipe Gesture are not working in YouTubePlayerView in full screen mode(在全屏模式下,滑动手势在 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.
- 等待视频添加到屏幕上.您可以为当前播放器设置一个
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>
您还可以设置取消回调或其他任何操作.这取决于你.
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 中不起作用
基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01