Skip to content

Commit a43a634

Browse files
committed
refactor: simplify audio playback
1 parent a8a96ab commit a43a634

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

js/app/guest/audio.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ export const audio = (() => {
1212
*/
1313
let audioEl = null;
1414

15-
/**
16-
* @type {Promise<void>|null}
17-
*/
18-
let canPlay = null;
19-
2015
let isPlay = false;
2116

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

33-
await canPlay;
34-
3528
music.disabled = true;
3629
try {
3730
await audioEl.play();
@@ -69,8 +62,6 @@ export const audio = (() => {
6962
audioEl.autoplay = false;
7063
audioEl.controls = false;
7164

72-
canPlay = new Promise((res) => audioEl.addEventListener('canplay', res, { once: true }));
73-
7465
const context = new AudioContext();
7566
const source = context.createMediaElementSource(audioEl);
7667
source.connect(context.destination);
@@ -86,8 +77,8 @@ export const audio = (() => {
8677
return;
8778
}
8879

89-
sourceBuffer.appendBuffer(value.buffer);
9080
sourceBuffer.addEventListener('updateend', push, { once: true });
81+
sourceBuffer.appendBuffer(value.buffer);
9182
});
9283

9384
push();

0 commit comments

Comments
 (0)