Passando a un'altra app sul telefono musica e voce si fermano e la partita va in pausa

Nascosta la pagina il browser non disegna più fotogrammi, e la musica (che sfuma a ogni fotogramma) restava
accesa. Ora Music.setAway ferma subito tutti i brani; voce e musichetta del cartello si fermano, la partita va
in pausa e riparte con Riprendi. Nello stato: Campomigliaio si collega dal bivio, dopo La Luna.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ApqNBvNbNCwXqR2RLo8QJh
This commit is contained in:
2026-10-24 14:32:47 +02:00
co-authored by Claude Opus 5.5
parent b9d2f1161c
commit ee6c03a04d
5 changed files with 56 additions and 2 deletions
+9 -1
View File
@@ -24,6 +24,14 @@ export class Music {
this.old = [];
this.duck = 1; // 1 = pieno; meno di 1 mentre parla qualcuno
this.hold = false; // in pausa: il brano sfuma e si ferma, poi riprende da dov'era
this.away = false; // pagina nascosta (sul telefono si è passati a un'altra app): tutto fermo subito
}
// Nascosta la pagina il browser non chiama più update (niente fotogrammi): i brani si fermano qui, di colpo.
// Tornati, update li fa ripartire da dov'erano (se non c'è la pausa).
setAway(away) {
this.away = away;
if (away) for (const a of [this.current?.audio, ...this.old]) a?.pause();
}
// Chiamata a ogni fotogramma con il brano voluto: avvia, cambia e sfuma.
@@ -39,7 +47,7 @@ export class Music {
const a = this.current.audio;
a.volume = a.volume < target ? Math.min(target, a.volume + step) : Math.max(target, a.volume - step);
if (this.hold && a.volume === 0 && !a.paused) a.pause();
else if (!this.hold && a.paused && a !== this.blocked) a.play().catch(() => { this.blocked = a; });
else if (!this.hold && !this.away && a.paused && a !== this.blocked) a.play().catch(() => { this.blocked = a; });
}
for (const a of this.old) a.volume = Math.max(0, a.volume - step);
this.old = this.old.filter(a => a.volume > 0 || (a.pause(), false));