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