stream: reconnect the player to live instead of stale buffer
Firefox kept resuming the <audio> element from a stale buffer after a pause, drifting behind the live point. Load the stream with an anti-cache query parameter, and on resume-from-pause reconnect to live rather than replaying the buffered audio. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
80f27d2795
commit
c6d642a945
1 changed files with 20 additions and 1 deletions
|
|
@ -43,11 +43,30 @@
|
|||
<div class="np-label"><span class="dot"></span>en cours</div>
|
||||
<div class="title" id="title">—</div>
|
||||
<div class="artist" id="artist"></div>
|
||||
<audio id="player" controls autoplay preload="none" src="/radio.mp3"></audio>
|
||||
<audio id="player" controls autoplay preload="none"></audio>
|
||||
</main>
|
||||
<script>
|
||||
const titleEl = document.getElementById("title");
|
||||
const artistEl = document.getElementById("artist");
|
||||
const player = document.getElementById("player");
|
||||
|
||||
// Flux « live » : un paramètre anti-cache force le navigateur à se
|
||||
// (re)connecter au direct au lieu de rejouer un buffer périmé.
|
||||
const liveUrl = () => "/radio.mp3?t=" + Date.now();
|
||||
function goLive() {
|
||||
player.src = liveUrl();
|
||||
player.load();
|
||||
player.play().catch(() => {});
|
||||
}
|
||||
goLive();
|
||||
|
||||
// Reprendre après une pause = revenir au direct, pas au point bufferisé.
|
||||
let wasPaused = false;
|
||||
player.addEventListener("pause", () => { wasPaused = true; });
|
||||
player.addEventListener("play", () => {
|
||||
if (wasPaused) { wasPaused = false; goLive(); }
|
||||
});
|
||||
|
||||
async function poll() {
|
||||
try {
|
||||
const r = await fetch("/nowplaying", { cache: "no-store" });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue