Added the ability to link to a specific time in the video

A new GET parameter 'timecode' is added, which takes a number of seconds.
Synonyms are 'time', 'timestamp' and 't'.
This commit is contained in:
Erik Thuning 2022-02-18 13:07:00 +01:00
parent f011c7901b
commit 4c0cd8d887

@ -2,13 +2,13 @@ document.addEventListener('DOMContentLoaded', init)
function init() {
var cookies = getCookies()
var args = getArgs()
var mainstream = document.querySelector('.main > video')
setupLoader(mainstream)
if(typeof localPresentation !== "undefined") {
doSetup(localPresentation, null)
} else {
var args = getArgs()
if(args.hasMore) {
document.getElementById('more-indicator').classList.toggle('hidden')
}
@ -70,7 +70,7 @@ function init() {
}
awaitLoad(function() {
setupBuffer(mainstream)
setupProgress(body, mainstream)
setupProgress(body, mainstream, args.timecode)
})
}
}
@ -79,7 +79,8 @@ function getArgs() {
var get = window.location.search.substring(1)
var out = {'presentation': null,
'playlist': null,
'hasMore': null}
'hasMore': null,
'timecode': 0}
get.split('&').forEach(function(arg) {
[name, value] = arg.split('=')
value = decodeURIComponent(value)
@ -100,6 +101,12 @@ function getArgs() {
case 'm':
out.hasMore = true
break
case 'timestamp':
case 'timecode':
case 'time':
case 't':
out.timecode = value
break;
case 'debug':
out.debug = true
break
@ -409,7 +416,7 @@ function setupPlaylist(body, playlistfile) {
}
}
function setupProgress(body, mainstream) {
function setupProgress(body, mainstream, starttime) {
var backdrop = document.querySelector('#progress-container')
var pb = document.querySelector('#progress')
var dragging = false
@ -419,7 +426,8 @@ function setupProgress(body, mainstream) {
var popup = document.querySelector('#progress-popup')
printTime(mainstream.duration, duration)
printTime(0, elapsed)
printTime(starttime, elapsed)
setTime(starttime)
function printTime(time, elem) {
var hours = (Math.floor(time / 3600) + '').padStart(2, '0')
@ -442,10 +450,13 @@ function setupProgress(body, mainstream) {
updateProgress(event.offsetX)
}
}
function set(event) {
function setPos(event) {
var pos = event.offsetX
updateProgress(pos)
var newtime = pos / backdrop.clientWidth * mainstream.duration
setTime(newtime)
}
function setTime(newtime) {
mainstream.currentTime = newtime
mainstream.dispatchEvent(new CustomEvent('sync'))
}
@ -464,13 +475,13 @@ function setupProgress(body, mainstream) {
}
backdrop.addEventListener('mousedown', startDrag)
backdrop.addEventListener('click', set)
backdrop.addEventListener('click', setPos)
body.addEventListener('mousemove', update)
body.addEventListener('mouseup', stopDrag)
mainstream.addEventListener('timeupdate', showPlayback)
window.setInterval(function() {
printTime(mainstream.currentTime, elapsed)
}, 1000)
}, 500)
}
function setupResSwitching(streamlist, defaultres) {