Bug 1580095 - Update youtube wrapper. r=pip-reviewers,mhowell

Depends on D179556

Differential Revision: https://phabricator.services.mozilla.com/D180873
This commit is contained in:
Niklas Baumgardner 2023-06-16 21:57:23 +00:00
parent de7d493744
commit e7cb292746

View File

@ -5,14 +5,19 @@
"use strict";
class PictureInPictureVideoWrapper {
constructor(video) {
this.player = video.closest("#movie_player")?.wrappedJSObject;
}
isLive(video) {
return !!document.querySelector(".ytp-live");
}
setMuted(video, shouldMute) {
let muteButton = document.querySelector("#player .ytp-mute-button");
if (video.muted !== shouldMute && muteButton) {
muteButton.click();
if (this.player) {
if (shouldMute) {
this.player.mute();
} else {
this.player.unMute();
}
} else {
video.muted = shouldMute;
}
@ -60,6 +65,19 @@ class PictureInPictureVideoWrapper {
shouldHideToggle(video) {
return !!video.closest(".ytd-video-preview");
}
setVolume(video, volume) {
if (this.player) {
this.player.setVolume(volume * 100);
} else {
video.volume = volume;
}
}
getVolume(video) {
if (this.player) {
return this.player.getVolume() / 100;
}
return video.volume;
}
}
this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper;