Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 2fda2a9

Browse files
authored
Fix Youtube playback issues (#3388)
1 parent 0e0c034 commit 2fda2a9

File tree

2 files changed

+62
-2
lines changed
  • app/src

2 files changed

+62
-2
lines changed

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ public void handleHoverEvent(MotionEvent aEvent) {
902902

903903
} else {
904904
GeckoSession session = mSession.getGeckoSession();
905-
if (session != null) {
905+
if (session != null && !isContextMenuVisible()) {
906906
session.getPanZoomController().onMotionEvent(aEvent);
907907
}
908908
}
@@ -1595,6 +1595,11 @@ public void reject() {
15951595
}
15961596
}
15971597

1598+
private boolean isContextMenuVisible() {
1599+
return (mContextMenu != null && mContextMenu.isVisible() ||
1600+
mSelectionMenu != null && mSelectionMenu.isVisible());
1601+
}
1602+
15981603
// GeckoSession.ContentDelegate
15991604

16001605
@Override

app/src/main/assets/web_extensions/webcompat_youtube/main.js

+56-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ const YT_SELECTORS = {
88
embedPlayer: '.html5-video-player',
99
largePlayButton: '.ytp-large-play-button',
1010
thumbnail: '.ytp-cued-thumbnail-overlay-image',
11-
embedTitle: '.ytp-title-text'
11+
embedTitle: '.ytp-title-text',
12+
queueHandle: 'ytd-playlist-panel-video-renderer',
13+
playbackControls: '.ytp-left-controls'
1214
};
1315
const ENABLE_LOGS = true;
1416
const logDebug = (...args) => ENABLE_LOGS && console.log(LOGTAG, ...args);
@@ -142,6 +144,56 @@ class YoutubeExtension {
142144
}
143145
}
144146

147+
// Fix for the draggable items to continue being draggable when a context menu is displayed.
148+
// https://github.com/MozillaReality/FirefoxReality/issues/2611
149+
fixQueueContextMenu() {
150+
const handles = document.querySelectorAll(YT_SELECTORS.queueHandle);
151+
for (var i=0; i<handles.length; i++) {
152+
handles[i].removeEventListener('contextmenu', this.onContextMenu);
153+
handles[i].addEventListener('contextmenu', this.onContextMenu);
154+
}
155+
}
156+
157+
onContextMenu(event) {
158+
setTimeout(() => {
159+
var evt = document.createEvent("MouseEvents");
160+
evt.initEvent("mouseup", true, true);
161+
event.target.dispatchEvent(evt);
162+
});
163+
164+
// This is supposed to prevent the context menu from showing but it doesn't seem to work
165+
event.preventDefault();
166+
event.stopPropagation();
167+
event.stopImmediatePropagation();
168+
return false;
169+
}
170+
171+
// Prevent the double click to reach the player to avoid double clicking
172+
// to trigger a playback forward event.
173+
// https://github.com/MozillaReality/FirefoxReality/issues/2947
174+
videoControlsForwardFix() {
175+
const playbackControls = document.querySelector(YT_SELECTORS.playbackControls);
176+
playbackControls.removeEventListener("touchstart", this.videoControlsOnTouchStart);
177+
playbackControls.addEventListener("touchstart", this.videoControlsOnTouchStart);
178+
playbackControls.removeEventListener("touchend", this.videoControlsOnTouchEnd);
179+
playbackControls.addEventListener("touchend", this.videoControlsOnTouchEnd);
180+
}
181+
182+
videoControlsOnTouchStart(evt) {
183+
evt.stopPropagation();
184+
return false;
185+
}
186+
187+
videoControlsOnTouchEnd(evt) {
188+
evt.stopPropagation();
189+
return false;
190+
}
191+
192+
playerFixes() {
193+
this.fixQueueContextMenu();
194+
this.videoControlsForwardFix();
195+
}
196+
145197
// Runs the callback when the video is ready (has loaded the first frame).
146198
waitForVideoReady(callback) {
147199
this.retry("VideoReady", () => {
@@ -235,6 +287,7 @@ youtube.overrideViewport();
235287
window.addEventListener('load', () => {
236288
logDebug('page load');
237289
youtube.overrideVideoProjection();
290+
youtube.fixQueueContextMenu();
238291
// Wait until video has loaded the first frame to force quality change.
239292
// This prevents the infinite spinner problem.
240293
// See https://github.com/MozillaReality/FirefoxReality/issues/1433
@@ -246,3 +299,5 @@ window.addEventListener('load', () => {
246299
window.addEventListener('pushstate', () => youtube.overrideVideoProjection());
247300
window.addEventListener('popstate', () => youtube.overrideVideoProjection());
248301
window.addEventListener('click', event => youtube.overrideClick(event));
302+
window.addEventListener('mouseup', event => youtube.playerFixes());
303+
window.addEventListener("yt-navigate-start", () => youtube.playerFixes());

0 commit comments

Comments
 (0)