diff --git a/frontend/script.js b/frontend/script.js index b586f3c..4f3c6d2 100644 --- a/frontend/script.js +++ b/frontend/script.js @@ -41,46 +41,44 @@ source.type = ctype; source.src = upstream; player.src(source); - const Button = videojs.getComponent("Button"); - const cbutton = {}; - cbutton.clickHandler = (ev) => { - player.trigger("chromecastRequested"); - } - cbutton.text = "Chromecast"; - - const bigCastButton = new Button(player, cbutton); - bigCastButton.addClass("fab"); - bigCastButton.addClass("fa-chromecast"); - bigCastButton.addClass("vjs-control"); - bigCastButton.addClass("vjs-button"); - bigCastButton.addClass("vjs-big-chromecast"); - - player.one("canplay", () => { - player.addChild(bigCastButton); - }); - - player.on("loadedmetadata", () => { - console.log("loadedmetadata"); - }); - - player.on("posterchange", () => { - console.log("posterchange"); - }); - - const smallCastButton = new Button(player, cbutton); - smallCastButton.addClass("fab"); - smallCastButton.addClass("fa-chromecast"); - 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); + const canPlayTypeRaw = player.canPlayType(ctype); + const canPlayType = (canPlayTypeRaw === "maybe") || (canPlayTypeRaw === "probably"); + if(canPlayType) { + const Button = videojs.getComponent("Button"); + const cbutton = {}; + cbutton.clickHandler = (ev) => { + player.trigger("chromecastRequested"); } - }); + cbutton.text = "Chromecast"; + + const bigCastButton = new Button(player, cbutton); + bigCastButton.addClass("fab"); + bigCastButton.addClass("fa-chromecast"); + bigCastButton.addClass("vjs-control"); + bigCastButton.addClass("vjs-button"); + bigCastButton.addClass("vjs-big-chromecast"); + player.addChild(bigCastButton); + + player.one("error", () => { + player.removeChild(bigCastButton); + }); + + player.one("play", () => { + player.removeChild(bigCastButton); + }); + + const smallCastButton = new Button(player, cbutton); + smallCastButton.addClass("fab"); + smallCastButton.addClass("fa-chromecast"); + smallCastButton.addClass("vjs-control"); + smallCastButton.addClass("vjs-button"); + player.controlBar.addChild(smallCastButton); + player.on("chromecastConnected", () => { + if(player.volume() > 0.3) { + player.volume(0.2); + } + }); + } } document.addEventListener("DOMContentLoaded", handleCount); xhr.addEventListener("load", handleCount);