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;
|
audio.src = url;
|
||||||
playMusic();
|
playMusic();
|
||||||
} else {
|
} else {
|
||||||
// This line will cause a lot of errors.
|
try {
|
||||||
// Setting src to "" will cause any pending .play()s to fail.
|
// This line will cause a lot of errors.
|
||||||
audio.src = "";
|
// Setting src to "" will cause any pending .play()s to fail.
|
||||||
|
audio.src = "";
|
||||||
|
} catch {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function playMusic() {
|
function playMusic() {
|
||||||
//Starts playing the music if it isn't muted and isn't already playing
|
//Starts playing the music if it isn't muted and isn't already playing
|
||||||
if (audio.src && audio.src != "" && audio.paused && !audio.muted)
|
try {
|
||||||
audio.play().catch(() => getPromiseFromEvent(window, 'click').then(audio.play));
|
if (audio.src && audio.src != "" && audio.paused && !audio.muted)
|
||||||
|
audio.play().catch(() => getPromiseFromEvent(window, 'click').then(audio.play));
|
||||||
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
function volumeSet(number) {
|
function volumeSet(number) {
|
||||||
|
@ -241,10 +245,15 @@
|
||||||
audio.loop = true;
|
audio.loop = true;
|
||||||
audio.id = "user-music";
|
audio.id = "user-music";
|
||||||
audio.style = "display:none;";
|
audio.style = "display:none;";
|
||||||
if (localStorage.audiovolume && localStorage.audiovolume >= 0 && localStorage.audiovolume <= 1)
|
if (localStorage.audiovolume && localStorage.audiovolume >= 0 && localStorage.audiovolume <= 1) {
|
||||||
audio.volume = localStorage.audiovolume; //Load volume
|
try {
|
||||||
else
|
audio.volume = localStorage.audiovolume; //Load volume
|
||||||
|
} catch {
|
||||||
|
audio.volume = 0.2; //Default volume
|
||||||
|
}
|
||||||
|
} else {
|
||||||
audio.volume = 0.2; //Default volume
|
audio.volume = 0.2; //Default volume
|
||||||
|
}
|
||||||
|
|
||||||
//Monkey patches and event listeners
|
//Monkey patches and event listeners
|
||||||
const oldPushState = history.pushState;
|
const oldPushState = history.pushState;
|
||||||
|
@ -379,9 +388,12 @@
|
||||||
volumeSlider.addEventListener('mousedown', onMouseDown);
|
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', () => {
|
musicmute.addEventListener('click', () => {
|
||||||
localStorage.audiomuted = audio.muted = musicmute.checked;
|
localStorage.audiomuted = musicmute.checked;
|
||||||
|
audio.muted = musicmute.checked;
|
||||||
playMusic();
|
playMusic();
|
||||||
})
|
})
|
||||||
volumeStepDwn.addEventListener('click', volumeDec);
|
volumeStepDwn.addEventListener('click', volumeDec);
|
||||||
|
|
Loading…
Reference in a new issue