Skip to content

Commit

Permalink
feat: add catch err audio
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Sep 1, 2024
1 parent 7883837 commit 7d93326
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions js/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@ export const audio = (() => {
audio.preload = 'auto';
};

const play = async () => {
music.disabled = true;
try {
await audio.play();
} catch (err) {
alert(err);
}
music.disabled = false;
};

const button = async (button) => {
if (button.getAttribute('data-status') !== 'true') {
await audio.play();
await play();
button.setAttribute('data-status', 'true');
button.innerHTML = '<i class="fa-solid fa-circle-pause spin-button"></i>';
return;
Expand All @@ -35,7 +45,7 @@ export const audio = (() => {

return {
init,
play: () => audio.play(),
play,
button,
showButton,
};
Expand Down

0 comments on commit 7d93326

Please sign in to comment.