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> <script src="{{ script }}"></script>
</head> </head>
<body> <body>
<video class="video-js" id="player" controls></video>
</body> </body>
</html> </html>

View File

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