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 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 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.