check content type before adding chromecast

This commit is contained in:
Roy Olav Purser 2021-05-25 08:44:20 +02:00
parent 82f8e6ea40
commit 358693035b
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -41,6 +41,9 @@
source.type = ctype; source.type = ctype;
source.src = upstream; source.src = upstream;
player.src(source); player.src(source);
const canPlayTypeRaw = player.canPlayType(ctype);
const canPlayType = (canPlayTypeRaw === "maybe") || (canPlayTypeRaw === "probably");
if(canPlayType) {
const Button = videojs.getComponent("Button"); const Button = videojs.getComponent("Button");
const cbutton = {}; const cbutton = {};
cbutton.clickHandler = (ev) => { cbutton.clickHandler = (ev) => {
@ -54,17 +57,14 @@
bigCastButton.addClass("vjs-control"); bigCastButton.addClass("vjs-control");
bigCastButton.addClass("vjs-button"); bigCastButton.addClass("vjs-button");
bigCastButton.addClass("vjs-big-chromecast"); bigCastButton.addClass("vjs-big-chromecast");
player.one("canplay", () => {
player.addChild(bigCastButton); player.addChild(bigCastButton);
player.one("error", () => {
player.removeChild(bigCastButton);
}); });
player.on("loadedmetadata", () => { player.one("play", () => {
console.log("loadedmetadata"); player.removeChild(bigCastButton);
});
player.on("posterchange", () => {
console.log("posterchange");
}); });
const smallCastButton = new Button(player, cbutton); const smallCastButton = new Button(player, cbutton);
@ -73,15 +73,13 @@
smallCastButton.addClass("vjs-control"); smallCastButton.addClass("vjs-control");
smallCastButton.addClass("vjs-button"); smallCastButton.addClass("vjs-button");
player.controlBar.addChild(smallCastButton); player.controlBar.addChild(smallCastButton);
player.one("play", () => {
player.removeChild(bigCastButton);
});
player.on("chromecastConnected", () => { player.on("chromecastConnected", () => {
if(player.volume() > 0.3) { if(player.volume() > 0.3) {
player.volume(0.2); player.volume(0.2);
} }
}); });
} }
}
document.addEventListener("DOMContentLoaded", handleCount); document.addEventListener("DOMContentLoaded", handleCount);
xhr.addEventListener("load", handleCount); xhr.addEventListener("load", handleCount);
})(); })();