load video from render
This commit is contained in:
@ -12,6 +12,4 @@
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/{{ data["font_awesome_version"] }}/css/all.min.css">
|
||||
<link rel="stylesheet" href="{{ data["custom_style"] }}">
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,33 +1,10 @@
|
||||
(() => {
|
||||
const findUpstreamVideo = () => {
|
||||
const search = new URLSearchParams(location.search);
|
||||
search.set("render", "false");
|
||||
const url = new URL(location.origin);
|
||||
url.pathname = location.pathname;
|
||||
url.search = search.toString();
|
||||
return url.href;
|
||||
}
|
||||
|
||||
const upstream = findUpstreamVideo();
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("HEAD", upstream, true);
|
||||
xhr.send();
|
||||
|
||||
let count = 2;
|
||||
const handleCount = () => {
|
||||
if(--count === 0) {
|
||||
handle();
|
||||
}
|
||||
}
|
||||
|
||||
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 ctype = xhr.getResponseHeader("Content-Type");
|
||||
const image = xhr.getResponseHeader("Custom-Poster");
|
||||
console.log(ctype);
|
||||
const options = {};
|
||||
options.controls = true;
|
||||
options.liveui = true;
|
||||
@ -38,14 +15,14 @@
|
||||
options.plugins.chromecast = {};
|
||||
options.plugins.chromecast.addButtonToControlBar = false;
|
||||
const player = videojs(video, options);
|
||||
if((image instanceof String) || ((typeof image) == "string")) {
|
||||
player.poster(image);
|
||||
if((info.poster instanceof String) || ((typeof info.poster) == "string")) {
|
||||
player.poster(info.poster);
|
||||
}
|
||||
const source = {};
|
||||
source.type = ctype;
|
||||
source.src = upstream;
|
||||
source.type = info.ctype;
|
||||
source.src = info.upstream;
|
||||
player.src(source);
|
||||
const canPlayTypeRaw = player.canPlayType(ctype);
|
||||
const canPlayTypeRaw = player.canPlayType(info.ctype);
|
||||
const canPlayType = (canPlayTypeRaw === "maybe") || (canPlayTypeRaw === "probably");
|
||||
if(canPlayType) {
|
||||
const Button = videojs.getComponent("Button");
|
||||
@ -84,6 +61,5 @@
|
||||
});
|
||||
}
|
||||
}
|
||||
document.addEventListener("DOMContentLoaded", handleCount);
|
||||
xhr.addEventListener("load", handleCount);
|
||||
document.addEventListener("DOMContentLoaded", handle);
|
||||
})();
|
||||
|
Reference in New Issue
Block a user