Bug 1829697 - fix Sonyliv subtitles display for PIP video player. r=pip-reviewers,kpatenio

Differential Revision: https://phabricator.services.mozilla.com/D176798
This commit is contained in:
Janvi Bajoria 2023-05-10 17:13:05 +00:00
parent 35eab701e2
commit fb445e036b
3 changed files with 41 additions and 1 deletions

View File

@ -195,7 +195,7 @@ let AVAILABLE_PIP_OVERRIDES;
sonyliv: {
"https://*.sonyliv.com/*": {
videoWrapperScriptPath: "video-wrappers/videojsWrapper.js",
videoWrapperScriptPath: "video-wrappers/sonyliv.js",
},
},

View File

@ -42,6 +42,7 @@ FINAL_TARGET_FILES.features["pictureinpicture@mozilla.org"]["video-wrappers"] +=
"video-wrappers/piped.js",
"video-wrappers/primeVideo.js",
"video-wrappers/radiocanada.js",
"video-wrappers/sonyliv.js",
"video-wrappers/tubi.js",
"video-wrappers/tubilive.js",
"video-wrappers/twitch.js",

View File

@ -0,0 +1,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
class PictureInPictureVideoWrapper {
setCaptionContainerObserver(video, updateCaptionsFunction) {
let container = document.querySelector(".player-ui-main-wrapper");
if (container) {
updateCaptionsFunction("");
const callback = function(mutationsList, observer) {
let text = container.querySelector(
`.text-track-wrapper:not([style*="display: none"])`
)?.innerText;
if (!text) {
updateCaptionsFunction("");
return;
}
updateCaptionsFunction(text);
};
// immediately invoke the callback function to add subtitles to the PiP window
callback([1], null);
let captionsObserver = new MutationObserver(callback);
captionsObserver.observe(container, {
attributes: false,
childList: true,
subtree: true,
});
}
}
}
this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;