smoother playback cursor on short songs + optimize

This commit is contained in:
ed 2023-05-06 16:31:04 +00:00
parent 8a98efb929
commit 8b0e66122f

View file

@ -1840,6 +1840,7 @@ var pbar = (function () {
html_txt = 'a', html_txt = 'a',
lastmove = 0, lastmove = 0,
mousepos = 0, mousepos = 0,
t_redraw = 0,
gradh = -1, gradh = -1,
grad; grad;
@ -1908,6 +1909,9 @@ var pbar = (function () {
bctx = bc.ctx, bctx = bc.ctx,
apos, adur; apos, adur;
if (!widget.is_open)
return;
bctx.clearRect(0, 0, bc.w, bc.h); bctx.clearRect(0, 0, bc.w, bc.h);
if (!mp || !mp.au || !isNum(adur = mp.au.duration) || !isNum(apos = mp.au.currentTime) || apos < 0 || adur < apos) if (!mp || !mp.au || !isNum(adur = mp.au.duration) || !isNum(apos = mp.au.currentTime) || apos < 0 || adur < apos)
@ -1970,6 +1974,7 @@ var pbar = (function () {
w = 8, w = 8,
apos, adur; apos, adur;
clearTimeout(t_redraw);
pctx.clearRect(0, 0, pc.w, pc.h); pctx.clearRect(0, 0, pc.w, pc.h);
if (!mp || !mp.au || !isNum(adur = mp.au.duration) || !isNum(apos = mp.au.currentTime) || apos < 0 || adur < apos) if (!mp || !mp.au || !isNum(adur = mp.au.duration) || !isNum(apos = mp.au.currentTime) || apos < 0 || adur < apos)
@ -1984,17 +1989,30 @@ var pbar = (function () {
} }
var sm = bc.w * 1.0 / adur, var sm = bc.w * 1.0 / adur,
t1 = s2ms(adur),
t2 = s2ms(apos),
x = sm * apos; x = sm * apos;
if (w && html_txt != t2) {
ebi('np_pos').textContent = html_txt = t2;
if (mpl.os_ctl)
navigator.mediaSession.setPositionState({
'duration': adur,
'position': apos,
'playbackRate': 1
});
}
if (!widget.is_open)
return;
pctx.fillStyle = '#573'; pctx.fillRect((x - w / 2) - 1, 0, w + 2, pc.h); pctx.fillStyle = '#573'; pctx.fillRect((x - w / 2) - 1, 0, w + 2, pc.h);
pctx.fillStyle = '#dfc'; pctx.fillRect((x - w / 2), 0, w, pc.h); pctx.fillStyle = '#dfc'; pctx.fillRect((x - w / 2), 0, w, pc.h);
pctx.lineWidth = 2.5; pctx.lineWidth = 2.5;
pctx.fillStyle = '#fff'; pctx.fillStyle = '#fff';
var t1 = s2ms(adur), var m1 = pctx.measureText(t1),
t2 = s2ms(apos),
m1 = pctx.measureText(t1),
m1b = pctx.measureText(t1 + ":88"), m1b = pctx.measureText(t1 + ":88"),
m2 = pctx.measureText(t2), m2 = pctx.measureText(t2),
yt = pc.h / 3 * 2.1, yt = pc.h / 3 * 2.1,
@ -2008,15 +2026,8 @@ var pbar = (function () {
pctx.fillText(t1, xt1, yt); pctx.fillText(t1, xt1, yt);
pctx.fillText(t2, xt2, yt); pctx.fillText(t2, xt2, yt);
if (w && html_txt != t2) { if (sm > 10)
ebi('np_pos').textContent = html_txt = t2; t_redraw = setTimeout(r.drawpos, sm > 50 ? 20 : 50);
if (mpl.os_ctl)
navigator.mediaSession.setPositionState({
'duration': adur,
'position': apos,
'playbackRate': 1
});
}
}; };
window.addEventListener('resize', r.onresize); window.addEventListener('resize', r.onresize);
@ -2189,6 +2200,7 @@ function next_song_cmn(e) {
return tree_neigh(1); return tree_neigh(1);
} }
toast.inf(10, L.mm_nof); toast.inf(10, L.mm_nof);
mpl.traversals = 0;
t_fchg = 0; t_fchg = 0;
} }
function prev_song(e) { function prev_song(e) {
@ -2305,6 +2317,8 @@ var mpui = (function () {
return; return;
} }
var paint = !MOBILE || document.hasFocus();
var pos = mp.au.currentTime; var pos = mp.au.currentTime;
if (!isNum(pos)) if (!isNum(pos))
pos = 0; pos = 0;
@ -2312,7 +2326,7 @@ var mpui = (function () {
// indicate playback state in ui // indicate playback state in ui
widget.paused(mp.au.paused); widget.paused(mp.au.paused);
if (++nth > 69) { if (paint && ++nth > 69) {
// android-chrome breaks aspect ratio with unannounced viewport changes // android-chrome breaks aspect ratio with unannounced viewport changes
nth = 0; nth = 0;
if (MOBILE) { if (MOBILE) {
@ -2321,13 +2335,13 @@ var mpui = (function () {
vbar.onresize(); vbar.onresize();
} }
} }
else { else if (paint) {
// draw current position in song // draw current position in song
if (!mp.au.paused) if (!mp.au.paused)
pbar.drawpos(); pbar.drawpos();
// occasionally draw buffered regions // occasionally draw buffered regions
if (++nth % 5 == 0) if (nth % 5 == 0)
pbar.drawbuf(); pbar.drawbuf();
} }
@ -7054,6 +7068,7 @@ function sandbox(tgt, rules, cls, html) {
'},1)</script></body></html>'; '},1)</script></body></html>';
var fr = mknod('iframe'); var fr = mknod('iframe');
fr.setAttribute('title', 'folder ' + tid + 'logue');
fr.setAttribute('sandbox', rules ? 'allow-' + rules.replace(/ /g, ' allow-') : ''); fr.setAttribute('sandbox', rules ? 'allow-' + rules.replace(/ /g, ' allow-') : '');
fr.setAttribute('srcdoc', html); fr.setAttribute('srcdoc', html);
tgt.innerHTML = ''; tgt.innerHTML = '';