From 7a35ab1d1e4381533cce9718d619cc36616ec262 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 5 Jul 2022 20:37:05 +0200 Subject: [PATCH] bbox: video seek / loop url params --- copyparty/web/baguettebox.js | 25 ++++++++++++++++++++++--- copyparty/web/browser.js | 11 ++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/copyparty/web/baguettebox.js b/copyparty/web/baguettebox.js index 1bb685dc..0df343e0 100644 --- a/copyparty/web/baguettebox.js +++ b/copyparty/web/baguettebox.js @@ -39,6 +39,7 @@ window.baguetteBox = (function () { vnext = sread('vmode') == 'C', loopA = null, loopB = null, + url_ts = null, resume_mp = false; var onFSC = function (e) { @@ -555,9 +556,10 @@ window.baguetteBox = (function () { options.afterShow(); }, 50); - if (options.onChange) + if (options.onChange && !url_ts) options.onChange(currentIndex, imagesElements.length); + url_ts = null; documentLastFocus = document.activeElement; btnClose.focus(); isOverlayVisible = true; @@ -852,10 +854,13 @@ window.baguetteBox = (function () { var t = v.currentTime; if (side == 1) loopA = t; if (side == 2) loopB = t; - toast.inf(5, 'Loop' + (side == 1 ? 'A' : 'B') + ': ' + f2f(t, 2)); + if (side) + toast.inf(5, 'Loop' + (side == 1 ? 'A' : 'B') + ': ' + f2f(t, 2)); - if (loopB !== null) + if (loopB !== null) { timer.add(loopchk); + sethash(window.location.hash.slice(1).split('&')[0] + '&t=' + (loopA || 0) + '-' + loopB); + } } function loopchk() { @@ -869,6 +874,10 @@ window.baguetteBox = (function () { v.currentTime = loopA || 0; } + function urltime(txt) { + url_ts = txt; + } + function mp_ctl() { var v = vid(); if (!vmute && v && mp.au && !mp.au.paused) { @@ -911,6 +920,15 @@ window.baguetteBox = (function () { playvid(true); v.muted = vmute; v.loop = vloop; + if (url_ts) { + var seek = ('' + url_ts).split('-'); + v.currentTime = seek[0]; + if (seek.length > 1) { + loopA = parseFloat(seek[0]); + loopB = parseFloat(seek[1]); + setloop(); + } + } } selbg(); mp_ctl(); @@ -986,6 +1004,7 @@ window.baguetteBox = (function () { showNext: showNextImage, showPrevious: showPreviousImage, relseek: relseek, + urltime: urltime, playpause: playpause, hide: hideOverlay, destroy: destroyPlugin diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index c149e9cd..0ea105a5 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -2323,9 +2323,13 @@ function scan_hash(v) { ts = null; if (m.length > 3) { - m = /^&[Tt=0]*([0-9]+[Mm:])?0*([0-9]+)[Ss]?$/.exec(m[3]); - if (m) { - ts = parseInt(m[1] || 0) * 60 + parseInt(m[2] || 0); + var tm = /^&[Tt=0]*([0-9]+[Mm:])?0*([0-9]+)[Ss]?$/.exec(m[3]); + if (tm) { + ts = parseInt(tm[1] || 0) * 60 + parseInt(tm[2] || 0); + } + tm = /^&[Tt=0]*([0-9\.]+)-([0-9\.]+)$/.exec(m[3]); + if (tm) { + ts = '' + tm[1] + '-' + tm[2]; } } @@ -2361,6 +2365,7 @@ function eval_hash() { return; clearInterval(t); + baguetteBox.urltime(ts); var im = QS('#ggrid a[ref="' + id + '"]'); im.click(); im.scrollIntoView();