mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 09:22:31 -06:00
better isNaN + fade + fix preload seek:
* use Number.isFinite or shim it, rejecting strings * fade-in/out was too quick on volumes < 100% * fades (especially -out) was too slow on chrome * seek to start if playing into the previously played file * and let π raise if it wants to
This commit is contained in:
parent
993213e2c0
commit
27f08cdbfa
|
@ -1287,7 +1287,7 @@ function MPlayer() {
|
||||||
r.ftimer = null;
|
r.ftimer = null;
|
||||||
r.fade_in = function () {
|
r.fade_in = function () {
|
||||||
r.fvol = 0;
|
r.fvol = 0;
|
||||||
r.fdir = 0.025;
|
r.fdir = 0.025 * r.vol * (CHROME ? 1.5 : 1);
|
||||||
if (r.au) {
|
if (r.au) {
|
||||||
r.ftid = r.au.tid;
|
r.ftid = r.au.tid;
|
||||||
r.au.play();
|
r.au.play();
|
||||||
|
@ -1297,7 +1297,7 @@ function MPlayer() {
|
||||||
};
|
};
|
||||||
r.fade_out = function () {
|
r.fade_out = function () {
|
||||||
r.fvol = r.vol;
|
r.fvol = r.vol;
|
||||||
r.fdir = -0.05;
|
r.fdir = -0.05 * r.vol * (CHROME ? 2 : 1);
|
||||||
r.ftid = r.au.tid;
|
r.ftid = r.au.tid;
|
||||||
fader();
|
fader();
|
||||||
};
|
};
|
||||||
|
@ -1312,14 +1312,14 @@ function MPlayer() {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var done = true;
|
var done = true;
|
||||||
r.fvol += r.fdir;
|
r.fvol += r.fdir / (r.fdir < 0 && r.fvol < r.vol / 4 ? 2 : 1);
|
||||||
if (r.fvol < 0) {
|
if (r.fvol < 0) {
|
||||||
r.fvol = 0;
|
r.fvol = 0;
|
||||||
r.au.pause();
|
r.au.pause();
|
||||||
mpl.pp();
|
mpl.pp();
|
||||||
|
|
||||||
var t = mp.au.currentTime - 0.8;
|
var t = mp.au.currentTime - 0.8;
|
||||||
if (isFinite(t))
|
if (isNum(t))
|
||||||
mp.au.currentTime = Math.max(t, 0);
|
mp.au.currentTime = Math.max(t, 0);
|
||||||
}
|
}
|
||||||
else if (r.fvol > r.vol)
|
else if (r.fvol > r.vol)
|
||||||
|
@ -1569,7 +1569,7 @@ var pbar = (function () {
|
||||||
|
|
||||||
pctx.clearRect(0, 0, pc.w, pc.h);
|
pctx.clearRect(0, 0, pc.w, pc.h);
|
||||||
|
|
||||||
if (!mp || !mp.au || isNaN(adur = mp.au.duration) || isNaN(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)
|
||||||
return; // not-init || unsupp-codec
|
return; // not-init || unsupp-codec
|
||||||
|
|
||||||
var sm = bc.w * 1.0 / adur,
|
var sm = bc.w * 1.0 / adur,
|
||||||
|
@ -1724,7 +1724,7 @@ function seek_au_sec(seek) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
console.log('seek: ' + seek);
|
console.log('seek: ' + seek);
|
||||||
if (!isFinite(seek))
|
if (!isNum(seek))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mp.au.currentTime = seek;
|
mp.au.currentTime = seek;
|
||||||
|
@ -2108,7 +2108,7 @@ var audio_eq = (function () {
|
||||||
vs = that.value,
|
vs = that.value,
|
||||||
v = parseFloat(vs);
|
v = parseFloat(vs);
|
||||||
|
|
||||||
if (isNaN(v) || v + '' != vs)
|
if (!isNum(v) || v + '' != vs)
|
||||||
throw new Error('inval band');
|
throw new Error('inval band');
|
||||||
|
|
||||||
if (sb == 'amp')
|
if (sb == 'amp')
|
||||||
|
@ -2251,6 +2251,9 @@ function play(tid, is_ev, seek) {
|
||||||
mp.au.onprogress = pbar.drawpos;
|
mp.au.onprogress = pbar.drawpos;
|
||||||
mp.au.onplaying = mpui.progress_updater;
|
mp.au.onplaying = mpui.progress_updater;
|
||||||
mp.au.onended = next_song;
|
mp.au.onended = next_song;
|
||||||
|
t = mp.au.currentTime;
|
||||||
|
if (isNum(t) && t > 0.1)
|
||||||
|
mp.au.currentTime = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mp.au.src = mp.au.rsrc = url;
|
mp.au.src = mp.au.rsrc = url;
|
||||||
|
@ -5054,7 +5057,7 @@ var treectl = (function () {
|
||||||
function scaletree(e) {
|
function scaletree(e) {
|
||||||
ev(e);
|
ev(e);
|
||||||
treesz += parseInt(this.getAttribute("step"));
|
treesz += parseInt(this.getAttribute("step"));
|
||||||
if (isNaN(treesz))
|
if (!isNum(treesz))
|
||||||
treesz = 16;
|
treesz = 16;
|
||||||
|
|
||||||
treesz = clamp(treesz, 2, 120);
|
treesz = clamp(treesz, 2, 120);
|
||||||
|
|
|
@ -2106,7 +2106,7 @@ function up2k_init(subtle) {
|
||||||
spd2 = (t.size / ((t.t_uploaded - t.t_uploading) / 1000.)) / (1024 * 1024.);
|
spd2 = (t.size / ((t.t_uploaded - t.t_uploading) / 1000.)) / (1024 * 1024.);
|
||||||
|
|
||||||
pvis.seth(t.n, 2, 'hash {0}, up {1} MB/s'.format(
|
pvis.seth(t.n, 2, 'hash {0}, up {1} MB/s'.format(
|
||||||
f2f(spd1, 2), isNaN(spd2) ? '--' : f2f(spd2, 2)));
|
f2f(spd1, 2), !isNum(spd2) ? '--' : f2f(spd2, 2)));
|
||||||
|
|
||||||
pvis.move(t.n, 'ok');
|
pvis.move(t.n, 'ok');
|
||||||
if (!pvis.ctr.bz && !pvis.ctr.q)
|
if (!pvis.ctr.bz && !pvis.ctr.q)
|
||||||
|
|
|
@ -108,7 +108,7 @@ catch (ex) {
|
||||||
console.log = console.stdlog;
|
console.log = console.stdlog;
|
||||||
console.log('console capture failed', ex);
|
console.log('console capture failed', ex);
|
||||||
}
|
}
|
||||||
var crashed = false, ignexd = {};
|
var crashed = false, ignexd = {}, evalex_fatal = false;
|
||||||
function vis_exh(msg, url, lineNo, columnNo, error) {
|
function vis_exh(msg, url, lineNo, columnNo, error) {
|
||||||
if ((msg + '').indexOf('ResizeObserver') + 1)
|
if ((msg + '').indexOf('ResizeObserver') + 1)
|
||||||
return; // chrome issue 809574 (benign, from <video>)
|
return; // chrome issue 809574 (benign, from <video>)
|
||||||
|
@ -119,7 +119,7 @@ function vis_exh(msg, url, lineNo, columnNo, error) {
|
||||||
if (!/\.js($|\?)/.exec('' + url))
|
if (!/\.js($|\?)/.exec('' + url))
|
||||||
return; // chrome debugger
|
return; // chrome debugger
|
||||||
|
|
||||||
if ((url + '').indexOf(' > eval') + 1)
|
if ((url + '').indexOf(' > eval') + 1 && !evalex_fatal)
|
||||||
return; // md timer
|
return; // md timer
|
||||||
|
|
||||||
var ekey = url + '\n' + lineNo + '\n' + msg;
|
var ekey = url + '\n' + lineNo + '\n' + msg;
|
||||||
|
@ -649,6 +649,14 @@ function s2ms(s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var isNum = function (v) {
|
||||||
|
var n = parseFloat(v);
|
||||||
|
return !isNaN(v - n) && n === v;
|
||||||
|
};
|
||||||
|
if (window.Number)
|
||||||
|
isNum = Number.isFinite;
|
||||||
|
|
||||||
|
|
||||||
function f2f(val, nd) {
|
function f2f(val, nd) {
|
||||||
// 10.toFixed(1) returns 10.00 for certain values of 10
|
// 10.toFixed(1) returns 10.00 for certain values of 10
|
||||||
val = (val * Math.pow(10, nd)).toFixed(0).split('.')[0];
|
val = (val * Math.pow(10, nd)).toFixed(0).split('.')[0];
|
||||||
|
@ -1406,8 +1414,10 @@ function repl(e) {
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
return toast.inf(3, 'eval aborted');
|
return toast.inf(3, 'eval aborted');
|
||||||
|
|
||||||
if (cmd.startsWith(','))
|
if (cmd.startsWith(',')) {
|
||||||
return modal.alert(esc(eval(cmd.slice(1)) + ''))
|
evalex_fatal = true;
|
||||||
|
return modal.alert(esc(eval(cmd.slice(1)) + ''));
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
modal.alert(esc(eval(cmd) + ''));
|
modal.alert(esc(eval(cmd) + ''));
|
||||||
|
|
Loading…
Reference in a new issue