add video tag from js

This commit is contained in:
Roy Olav Purser 2021-05-12 10:26:15 +02:00
parent 8efc686f83
commit 8fbf8a4f62
Signed by: roypur
GPG Key ID: E14D26A036F21656
2 changed files with 16 additions and 11 deletions

View File

@ -5,6 +5,5 @@
<script src="{{ script }}"></script>
</head>
<body>
<video class="video-js" id="player" controls></video>
</body>
</html>

View File

@ -1,13 +1,19 @@
document.addEventListener("DOMContentLoaded", () => {
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
let ctype = xhr.getResponseHeader("Content-Type");
let player = videojs("player");
let source = {};
source.type = ctype;
source.src = "{{ stream }}";
player.src(source);
let bodies = document.getElementsByTagName("body");
if(bodies.length === 1) {
let body = bodies[0];
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
let video = document.createElement("video");
body.appendChild(video);
let ctype = xhr.getResponseHeader("Content-Type");
let player = videojs(video);
let source = {};
source.type = ctype;
source.src = "{{ stream }}";
player.src(source);
}
xhr.open("HEAD", "{{ stream }}", true);
xhr.send();
}
xhr.open("HEAD", "{{ stream }}", true);
xhr.send();
});