Skip to content

Commit

Permalink
Fix controllers disappearing
Browse files Browse the repository at this point in the history
This fixes a bug with video websites like https://www.ixigua.com/

The following sequence of steps:

- enter fullscreen mode
- leave fullscreen mode
- play the video

left the app in an unusable state because the controllers became hidden
and the user was not able to get them to appear again.

The cause was that when the page first enters fullscreen mode,
`NavigationBarWidget.onFullScreen` added a listener to the window
which would wait for the current video to become available
and would then update the UI for fullscreen mode.

That listener was not being removed when the page left fullscreen mode,
so when the user played the video later on, the listener would get
 activated and would try to transition the UI to fullscreen mode.
 This was leaving the app in an inconsistent state so clicks on the
 background were being ignored (`onWorldClick`).

 The fix is to ensure that the window listener is removed when the page
 leavs fullscreen mode.

 Just in case, `onWorldClick` will make the controllers visible by default.

 Fixes #1181
  • Loading branch information
felipeerias committed Jan 23, 2024
1 parent 3620d69 commit 41d6bd5
Showing 1 changed file with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ public void onSessionChanged(@NonNull Session aOldSession, @NonNull Session aSes
mAttachedWindow.setIsFullScreen(false);
}

private void onEnterFullScreen(@NonNull WindowWidget aWindow) {
private void onEnterFullScreen() {
enterFullScreenMode();

mBeforeFullscreenPlacement = mWidgetPlacement.clone();
Expand Down Expand Up @@ -693,30 +693,33 @@ private void onEnterFullScreen(@NonNull WindowWidget aWindow) {
mAttachedWindow.reCenterFrontWindow();
}

private final WindowWidget.WindowListener onFullscreenVideoWindowListener =
new WindowWidget.WindowListener() {
@Override
public void onVideoAvailabilityChanged(@NonNull WindowWidget aWindow) {
assert getSession().getActiveVideo() != null;
onEnterFullScreen();
mAttachedWindow.removeWindowListener(this);
}

@Override
public void onMediaFullScreen(@NonNull WMediaSession mediaSession, boolean aFullScreen) {
assert getSession().getFullScreenVideo() != null;
onEnterFullScreen();
mAttachedWindow.removeWindowListener(this);
}
};

@Override
public void onFullScreen(@NonNull WindowWidget aWindow, boolean aFullScreen) {
if (aFullScreen) {
if (getSession().getFullScreenVideo() != null) {
onEnterFullScreen(aWindow);
onEnterFullScreen();
} else {
// No active fullscreen video. There might be two reasons for that:
// 1. The video is not active yet -> wait for onVideoAvailabilityChanged
// 2. The video is active but not in fullscreen -> wait for onMediaFullscreen
mAttachedWindow.addWindowListener(new WindowWidget.WindowListener() {
@Override
public void onVideoAvailabilityChanged(@NonNull WindowWidget aWindow) {
WindowWidget.WindowListener.super.onVideoAvailabilityChanged(aWindow);
assert getSession().getActiveVideo() != null;
onEnterFullScreen(aWindow);
mAttachedWindow.removeWindowListener(this);
}
@Override
public void onMediaFullScreen(@NonNull WMediaSession mediaSession, boolean aFullScreen) {
assert getSession().getFullScreenVideo() != null;
onEnterFullScreen(aWindow);
mAttachedWindow.removeWindowListener(this);
}
});
mAttachedWindow.addWindowListener(onFullscreenVideoWindowListener);
}
} else {
mWidgetPlacement = mBeforeFullscreenPlacement;
Expand All @@ -726,6 +729,7 @@ public void onMediaFullScreen(@NonNull WMediaSession mediaSession, boolean aFull
exitVRVideo();
}
exitFullScreenMode();
mAttachedWindow.removeWindowListener(onFullscreenVideoWindowListener);
mAttachedWindow.centerFrontWindowIfNeeded();
}
}
Expand Down Expand Up @@ -1285,6 +1289,9 @@ public void onWorldClick() {
AnimationHelper.fadeIn(mBinding.navigationBarFullscreen.fullScreenModeContainer, 0, null);
}
}
} else {
// Ensure that the controllers are visible, just in case.
mWidgetManager.setControllersVisible(true);
}
closeFloatingMenus();
}
Expand Down

0 comments on commit 41d6bd5

Please sign in to comment.