forked from mirrors/akkoma-fe
attempt error catching
This commit is contained in:
parent
e137304840
commit
2378d4c595
1 changed files with 22 additions and 10 deletions
|
@ -33,16 +33,20 @@
|
|||
audio.src = url;
|
||||
playMusic();
|
||||
} else {
|
||||
try {
|
||||
// This line will cause a lot of errors.
|
||||
// Setting src to "" will cause any pending .play()s to fail.
|
||||
audio.src = "";
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
function playMusic() {
|
||||
//Starts playing the music if it isn't muted and isn't already playing
|
||||
try {
|
||||
if (audio.src && audio.src != "" && audio.paused && !audio.muted)
|
||||
audio.play().catch(() => getPromiseFromEvent(window, 'click').then(audio.play));
|
||||
} catch {}
|
||||
}
|
||||
|
||||
function volumeSet(number) {
|
||||
|
@ -241,10 +245,15 @@
|
|||
audio.loop = true;
|
||||
audio.id = "user-music";
|
||||
audio.style = "display:none;";
|
||||
if (localStorage.audiovolume && localStorage.audiovolume >= 0 && localStorage.audiovolume <= 1)
|
||||
if (localStorage.audiovolume && localStorage.audiovolume >= 0 && localStorage.audiovolume <= 1) {
|
||||
try {
|
||||
audio.volume = localStorage.audiovolume; //Load volume
|
||||
else
|
||||
} catch {
|
||||
audio.volume = 0.2; //Default volume
|
||||
}
|
||||
} else {
|
||||
audio.volume = 0.2; //Default volume
|
||||
}
|
||||
|
||||
//Monkey patches and event listeners
|
||||
const oldPushState = history.pushState;
|
||||
|
@ -379,9 +388,12 @@
|
|||
volumeSlider.addEventListener('mousedown', onMouseDown);
|
||||
}
|
||||
|
||||
audio.muted = musicmute.checked = localStorage.audiomuted === "true";
|
||||
localStorage.audiomuted === "true";
|
||||
audio.muted = localStorage.audiomuted;
|
||||
musicmute.checked = localStorage.audiomuted;
|
||||
musicmute.addEventListener('click', () => {
|
||||
localStorage.audiomuted = audio.muted = musicmute.checked;
|
||||
localStorage.audiomuted = musicmute.checked;
|
||||
audio.muted = musicmute.checked;
|
||||
playMusic();
|
||||
})
|
||||
volumeStepDwn.addEventListener('click', volumeDec);
|
||||
|
|
Loading…
Reference in a new issue