owncast/webroot/js/player/player.js

74 lines
1.5 KiB
JavaScript
Raw Normal View History

// style hackings
window.VIDEOJS_NO_DYNAMIC_STYLE = true;
2020-06-19 00:38:06 +03:00
// Create the player for the first time
2020-07-05 11:08:22 +03:00
const player = videojs(VIDEO_ID, null, function () {
getStatus();
setInterval(getStatus, 5000);
setupPlayerEventHandlers();
})
2020-06-19 00:38:06 +03:00
player.ready(function () {
console.log('Player ready.')
resetPlayer(player);
});
function resetPlayer(player) {
2020-06-19 06:46:00 +03:00
player.reset();
2020-07-05 11:08:22 +03:00
player.src({ type: 'application/x-mpegURL', src: URL_STREAM });
setVideoPoster(app.isOnline);
}
2020-06-19 00:38:06 +03:00
function setupPlayerEventHandlers() {
2020-07-05 11:08:22 +03:00
const player = videojs(VIDEO_ID);
player.on('error', function (e) {
console.log("Player error: ", e);
})
// player.on('loadeddata', function (e) {
// console.log("loadeddata");
// })
player.on('ended', function (e) {
console.log("ended");
resetPlayer(player);
})
//
// player.on('abort', function (e) {
// console.log("abort");
// })
//
// player.on('durationchange', function (e) {
// console.log("durationchange");
// })
//
// player.on('stalled', function (e) {
// console.log("stalled");
// })
//
2020-06-19 06:46:00 +03:00
player.on('playing', function (e) {
2020-06-19 22:19:18 +03:00
if (playerRestartTimer) {
clearTimeout(playerRestartTimer);
}
2020-06-19 06:46:00 +03:00
})
//
// player.on('waiting', function (e) {
// // console.log("waiting");
// })
}
function restartPlayer() {
try {
2020-07-05 11:08:22 +03:00
console.log('restarting', player.src())
const player = videojs(VIDEO_ID);
2020-06-19 06:46:00 +03:00
player.pause();
player.src(player.src()); // Reload the same video
player.load();
player.play();
} catch (e) {
console.log(e)
}
2020-07-05 11:08:22 +03:00
}