2020-06-26 02:44:47 +02:00
|
|
|
const streamURL = '/hls/stream.m3u8';
|
|
|
|
// const streamURL = 'https://goth.land/hls/stream.m3u8'; // Uncomment me to point to remote video
|
2020-06-18 23:38:06 +02:00
|
|
|
|
2020-06-18 00:02:50 +02:00
|
|
|
// style hackings
|
|
|
|
window.VIDEOJS_NO_DYNAMIC_STYLE = true;
|
|
|
|
|
2020-06-18 23:38:06 +02:00
|
|
|
// Create the player for the first time
|
|
|
|
const player = videojs('video', null, function () {
|
2020-06-18 00:02:50 +02:00
|
|
|
getStatus();
|
|
|
|
setInterval(getStatus, 5000);
|
|
|
|
setupPlayerEventHandlers();
|
2020-06-18 02:13:55 +02:00
|
|
|
})
|
2020-06-18 00:02:50 +02:00
|
|
|
|
2020-06-18 23:38:06 +02:00
|
|
|
player.ready(function () {
|
|
|
|
console.log('Player ready.')
|
2020-06-26 06:24:43 +02:00
|
|
|
resetPlayer(player);
|
|
|
|
});
|
|
|
|
|
|
|
|
function resetPlayer(player) {
|
2020-06-19 05:46:00 +02:00
|
|
|
player.reset();
|
2020-06-18 23:38:06 +02:00
|
|
|
player.src({ type: 'application/x-mpegURL', src: streamURL });
|
2020-06-26 06:24:43 +02:00
|
|
|
if (app.isOnline) {
|
|
|
|
player.poster('/thumbnail.jpg');
|
|
|
|
} else {
|
|
|
|
// Change this to some kind of offline image.
|
|
|
|
player.poster('/img/logo.png');
|
|
|
|
}
|
|
|
|
}
|
2020-06-18 23:38:06 +02:00
|
|
|
|
2020-06-18 00:02:50 +02:00
|
|
|
function setupPlayerEventHandlers() {
|
|
|
|
const player = videojs('video');
|
|
|
|
|
|
|
|
player.on('error', function (e) {
|
2020-06-18 02:48:33 +02:00
|
|
|
console.log("Player error: ", e);
|
2020-06-18 00:02:50 +02:00
|
|
|
})
|
|
|
|
|
2020-06-18 02:48:33 +02:00
|
|
|
// player.on('loadeddata', function (e) {
|
|
|
|
// console.log("loadeddata");
|
|
|
|
// })
|
2020-06-18 00:02:50 +02:00
|
|
|
|
2020-06-26 06:24:43 +02:00
|
|
|
player.on('ended', function (e) {
|
|
|
|
console.log("ended");
|
|
|
|
resetPlayer(player);
|
|
|
|
})
|
2020-06-18 02:48:33 +02:00
|
|
|
//
|
2020-06-18 00:02:50 +02:00
|
|
|
// player.on('abort', function (e) {
|
|
|
|
// console.log("abort");
|
|
|
|
// })
|
2020-06-18 02:48:33 +02:00
|
|
|
//
|
2020-06-18 00:02:50 +02:00
|
|
|
// player.on('durationchange', function (e) {
|
|
|
|
// console.log("durationchange");
|
|
|
|
// })
|
2020-06-18 02:48:33 +02:00
|
|
|
//
|
2020-06-18 00:02:50 +02:00
|
|
|
// player.on('stalled', function (e) {
|
|
|
|
// console.log("stalled");
|
|
|
|
// })
|
2020-06-18 02:48:33 +02:00
|
|
|
//
|
2020-06-19 05:46:00 +02:00
|
|
|
player.on('playing', function (e) {
|
2020-06-19 21:19:18 +02:00
|
|
|
if (playerRestartTimer) {
|
|
|
|
clearTimeout(playerRestartTimer);
|
|
|
|
}
|
2020-06-19 05:46:00 +02:00
|
|
|
})
|
2020-06-18 02:48:33 +02:00
|
|
|
//
|
|
|
|
// player.on('waiting', function (e) {
|
|
|
|
// // console.log("waiting");
|
|
|
|
// })
|
2020-06-18 00:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function restartPlayer() {
|
|
|
|
try {
|
2020-06-19 05:46:00 +02:00
|
|
|
console.log('restarting')
|
2020-06-18 00:02:50 +02:00
|
|
|
const player = videojs('video');
|
2020-06-19 05:46:00 +02:00
|
|
|
player.pause();
|
2020-06-18 00:02:50 +02:00
|
|
|
player.src(player.src()); // Reload the same video
|
|
|
|
player.load();
|
|
|
|
player.play();
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|