Skip to content

Commit

Permalink
refactor: simplify audio playback
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Mar 5, 2025
1 parent a8a96ab commit a43a634
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions js/app/guest/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ export const audio = (() => {
*/
let audioEl = null;

/**
* @type {Promise<void>|null}
*/
let canPlay = null;

let isPlay = false;

const statePlay = '<i class="fa-solid fa-circle-pause spin-button"></i>';
Expand All @@ -30,8 +25,6 @@ export const audio = (() => {
return;
}

await canPlay;

music.disabled = true;
try {
await audioEl.play();
Expand Down Expand Up @@ -69,8 +62,6 @@ export const audio = (() => {
audioEl.autoplay = false;
audioEl.controls = false;

canPlay = new Promise((res) => audioEl.addEventListener('canplay', res, { once: true }));

const context = new AudioContext();
const source = context.createMediaElementSource(audioEl);
source.connect(context.destination);
Expand All @@ -86,8 +77,8 @@ export const audio = (() => {
return;
}

sourceBuffer.appendBuffer(value.buffer);
sourceBuffer.addEventListener('updateend', push, { once: true });
sourceBuffer.appendBuffer(value.buffer);
});

push();
Expand Down

0 comments on commit a43a634

Please sign in to comment.