-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (42 loc) · 1.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Import stylesheets
import "./style.css";
import videojs from "video.js";
var options = {
controls: true,
autoplay: true,
preload: "auto",
liveui: true,
html5: {
hls: {
// When this option is set to true,
// in Safari there is an issue with
// live streams where the player starts
// playing from position zero instead of
// from live position.
overrideNative: false
}
},
techOrder: ["html5"]
};
var isPlayerReady = false;
var player = videojs("videoPlayer", options, function onPlayerReady() {
videojs.log("Player is ready!");
isPlayerReady = true;
});
function play() {
if (isPlayerReady === false) {
alert("The player is not ready yet.");
return;
}
var urlInputElement = document.getElementById("urlInput");
var url = urlInputElement.value;
var contentType = "video/mp4";
if (url.includes(".m3u8")) {
contentType = "application/x-mpegURL";
}
player.src({ type: contentType, src: url });
player.on("ready", function() {
player.play();
});
}
document.getElementById("playButton").addEventListener("click", play);