78 lines
2.9 KiB
JavaScript
78 lines
2.9 KiB
JavaScript
(() => {
|
|
const info = {% raw info %};
|
|
const handle = () => {
|
|
const [body] = document.getElementsByTagName("body");
|
|
const video = document.createElement("video");
|
|
video.className = "video-js vjs-big-play-centered";
|
|
body.appendChild(video);
|
|
const options = {};
|
|
options.controls = true;
|
|
options.liveui = true;
|
|
options.responsive = true;
|
|
options.fill = true;
|
|
options.techOrder = ["chromecast", "html5"];
|
|
options.plugins = {};
|
|
options.plugins.chromecast = {};
|
|
options.plugins.chromecast.addButtonToControlBar = false;
|
|
const player = videojs(video, options);
|
|
if((info.poster instanceof String) || ((typeof info.poster) == "string")) {
|
|
player.poster(info.poster);
|
|
}
|
|
const source = {};
|
|
source.type = info.ctype;
|
|
source.src = info.upstream;
|
|
player.src(source);
|
|
const canPlayTypeRaw = player.canPlayType(info.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 bigCastButtonWrapper = new Button(player, cbutton);
|
|
const bigCastButton = bigCastButtonWrapper.el();
|
|
for(const elem of bigCastButton.children) {
|
|
bigCastButton.removeChild(elem);
|
|
}
|
|
bigCastButton.classList.add("vjs-control");
|
|
bigCastButton.classList.add("vjs-button");
|
|
bigCastButton.classList.add("fab");
|
|
bigCastButton.classList.add("fa-chromecast");
|
|
bigCastButton.classList.add("vjs-big-chromecast");
|
|
player.addChild(bigCastButtonWrapper);
|
|
|
|
player.one("error", () => {
|
|
player.removeChild(bigCastButtonWrapper);
|
|
});
|
|
|
|
player.one("play", () => {
|
|
player.removeChild(bigCastButtonWrapper);
|
|
});
|
|
|
|
const smallCastButtonWrapper = new Button(player, cbutton);
|
|
const smallCastButton = smallCastButtonWrapper.el();
|
|
smallCastButton.classList.add("vjs-control");
|
|
smallCastButton.classList.add("vjs-button");
|
|
|
|
for(const elem of smallCastButton.children) {
|
|
if(elem.classList.contains("vjs-icon-placeholder")) {
|
|
elem.classList.add("fab");
|
|
elem.classList.add("fa-chromecast");
|
|
}
|
|
}
|
|
|
|
player.controlBar.addChild(smallCastButtonWrapper);
|
|
|
|
player.on("chromecastConnected", () => {
|
|
if(player.volume() > 0.3) {
|
|
player.volume(0.2);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
document.addEventListener("DOMContentLoaded", handle);
|
|
})();
|