fixxes for background playbacks
This commit is contained in:
+23
-31
@@ -156,44 +156,36 @@
|
||||
const stop = document.getElementById('auto-stop');
|
||||
const status = document.getElementById('auto-status');
|
||||
|
||||
start.onclick = () => {
|
||||
start.onclick = async () => {
|
||||
const imin = Math.max(1, parseInt(document.getElementById('auto-interval-min').value, 10) || 5);
|
||||
const imax = Math.max(imin, parseInt(document.getElementById('auto-interval-max').value, 10) || 10);
|
||||
const dmin = Math.max(0, parseInt(document.getElementById('auto-delay-min').value, 10) || 3);
|
||||
const dmax = Math.max(dmin, parseInt(document.getElementById('auto-delay-max').value, 10) || 12);
|
||||
|
||||
const delayMs = randBetween(dmin, dmax) * 60 * 1000;
|
||||
scheduleAuto(imin, imax, delayMs, status, start, stop);
|
||||
const res = await fetch('/api/soundboard/auto_start', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ interval_min: imin, interval_max: imax, delay_min: dmin, delay_max: dmax })
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
status.textContent = `Aktiv (nächster in ${(data.next_seconds/60).toFixed(1)} min)`;
|
||||
start.disabled = true;
|
||||
stop.disabled = false;
|
||||
} else {
|
||||
statusBox(data.message || 'Auto-Start fehlgeschlagen', 'warn');
|
||||
}
|
||||
};
|
||||
|
||||
stop.onclick = () => stopAuto(status, start, stop);
|
||||
}
|
||||
|
||||
function randBetween(min, max) {
|
||||
return min + Math.random() * (max - min);
|
||||
}
|
||||
|
||||
function scheduleAuto(imin, imax, delayMs, status, startBtn, stopBtn) {
|
||||
stopAuto(status, startBtn, stopBtn);
|
||||
status.textContent = `Geplant in ${(delayMs/60000).toFixed(1)} min`;
|
||||
startBtn.disabled = true;
|
||||
stopBtn.disabled = false;
|
||||
autoTimer = setTimeout(async function tick() {
|
||||
await playRandom();
|
||||
const nextMs = randBetween(imin, imax) * 60 * 1000;
|
||||
status.textContent = `Nächster in ${(nextMs/60000).toFixed(1)} min`;
|
||||
autoTimer = setTimeout(tick, nextMs);
|
||||
}, delayMs);
|
||||
}
|
||||
|
||||
function stopAuto(status, startBtn, stopBtn) {
|
||||
if (autoTimer) {
|
||||
clearTimeout(autoTimer);
|
||||
autoTimer = null;
|
||||
}
|
||||
if (status) status.textContent = 'Aus';
|
||||
if (startBtn) startBtn.disabled = false;
|
||||
if (stopBtn) stopBtn.disabled = true;
|
||||
stop.onclick = async () => {
|
||||
const res = await fetch('/api/soundboard/auto_stop', { method: 'POST' });
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
status.textContent = 'Aus';
|
||||
start.disabled = false;
|
||||
stop.disabled = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function playSound(sound) {
|
||||
|
||||
Reference in New Issue
Block a user