更新时间:2023-02-26 21:35:29
迟到总比没有好.
问题等同于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
回调方法中执行以下代码.以下代码将添加一个透明对话框,该对话框将位于视图层次结构的顶部(甚至高于视频):
PlayerStateChangeListener
to your current player and execute the following code in onVideoStarted
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 ***Player 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.