Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
web: Check for errors before using preloaded song.
Browse files Browse the repository at this point in the history
Make the music-player component check that the preloaded
audio element didn't report any errors before trying to use
it. When preloading fails due to a network error, the
element appears to get stuck in a state where it throws "The
element has no supported sources." exceptions even after the
network is back. Fixes #16.
  • Loading branch information
derat committed May 6, 2021
1 parent dabd997 commit de01938
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion web/music-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,11 @@ customElements.define(
const ctx = this.gainNode_.context;
if (ctx.state === 'suspended') ctx.resume();

if (this.nextAudio_ && this.nextAudio_.src == url) {
if (
this.nextAudio_ &&
this.nextAudio_.src === url &&
this.nextAudio_.error === null
) {
console.log(`Starting preloaded ${song.songId} (${url})`);
this.swapAudio_(this.nextAudio_);
} else {
Expand Down

0 comments on commit de01938

Please sign in to comment.