Skip to content

Commit 658f565

Browse files
committed
Revert "feat: add audio playback functionality with caching"
This reverts commit e6d1d5d.
1 parent d5201d6 commit 658f565

File tree

2 files changed

+7
-41
lines changed

2 files changed

+7
-41
lines changed

js/app/guest/audio.js

+6-38
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { request, HTTP_GET } from '../../connection/request.js';
2-
31
export const audio = (() => {
42

53
/**
@@ -12,11 +10,6 @@ export const audio = (() => {
1210
*/
1311
let audioEl = null;
1412

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

2215
const statePlay = '<i class="fa-solid fa-circle-pause spin-button"></i>';
@@ -58,47 +51,22 @@ export const audio = (() => {
5851
*/
5952
const init = () => {
6053
music = document.getElementById('button-music');
61-
document.addEventListener('undangan.open', () => {
62-
music.style.display = 'block';
63-
});
54+
music.style.display = 'block';
6455

65-
const url = music.getAttribute('data-url');
66-
const mediaSource = new MediaSource();
67-
audioEl = new Audio(URL.createObjectURL(mediaSource));
56+
audioEl = new Audio(music.getAttribute('data-url'));
57+
audioEl.volume = 1;
6858
audioEl.loop = true;
59+
audioEl.muted = false;
60+
audioEl.currentTime = 0;
6961
audioEl.autoplay = false;
7062
audioEl.controls = false;
7163

72-
canPlay = new Promise((res) => audioEl.addEventListener('canplay', res, { once: true }));
73-
74-
const context = new AudioContext();
75-
const source = context.createMediaElementSource(audioEl);
76-
source.connect(context.destination);
77-
78-
mediaSource.addEventListener('sourceopen', async () => {
79-
const sourceBuffer = mediaSource.addSourceBuffer('audio/mpeg');
80-
const res = await request(HTTP_GET, url).default();
81-
const reader = res.body.getReader();
82-
83-
const push = () => reader.read().then(({ value, done }) => {
84-
if (done) {
85-
mediaSource.endOfStream();
86-
return;
87-
}
88-
89-
sourceBuffer.appendBuffer(value.buffer);
90-
sourceBuffer.addEventListener('updateend', push, { once: true });
91-
});
92-
93-
push();
94-
});
95-
64+
audioEl.addEventListener('canplay', play);
9665
music.addEventListener('offline', pause);
9766
music.addEventListener('click', () => isPlay ? pause() : play());
9867
};
9968

10069
return {
10170
init,
102-
play,
10371
};
10472
})();

js/app/guest/guest.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,14 @@ export const guest = (() => {
127127
*/
128128
const open = (button) => {
129129
button.disabled = true;
130-
document.dispatchEvent(new Event('undangan.open'));
131130
document.body.scrollIntoView({ behavior: 'instant' });
132131

133132
if (theme.isAutoMode()) {
134133
document.getElementById('button-theme').style.display = 'block';
135134
}
136135

137136
slide();
138-
audio.play();
137+
audio.init();
139138
theme.spyTop();
140139

141140
basicAnimation();
@@ -233,7 +232,6 @@ export const guest = (() => {
233232
* @returns {void}
234233
*/
235234
const domLoaded = () => {
236-
audio.init();
237235
offline.init();
238236
progress.init();
239237
information = storage('information');

0 commit comments

Comments
 (0)