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