something

This commit is contained in:
2026-04-03 09:55:42 +02:00
parent 94710dbd9e
commit 28f5796ee5
17 changed files with 75 additions and 157 deletions
+10 -3
View File
@@ -9,6 +9,12 @@ class WebSocketAudioPlayer {
this.started = false;
}
_trimBuffer() {
if (!this.sourceBuffer.updating && this.audio.currentTime > 5) {
this.sourceBuffer.remove(0, this.audio.currentTime - 2);
}
}
start() {
this.audio = new Audio();
this.mediaSource = new MediaSource();
@@ -20,11 +26,11 @@ class WebSocketAudioPlayer {
this.ws = new WebSocket(this.url);
this.ws.binaryType = 'arraybuffer';
this.ws.onopen = () => this.ws.send(JSON.stringify({ type: 'fallback', data: 'mp3' }));
this.ws.onmessage = (event) => {
this.queue.push(event.data);
this._appendNext();
if (!this.started && this.queue.length === 0) { this.audio.play(); this.started = true; }
this._trimBuffer();
};
this.ws.onclose = () => {
if (this.mediaSource.readyState === 'open') this.mediaSource.endOfStream();
@@ -99,7 +105,7 @@ function OnPlayButtonClick(_ev) {
}
$playbutton.addClass('bg-gray').prop('disabled', true);
setTimeout(() => $playbutton.removeClass('bg-gray').prop('disabled', false), 3000);
setTimeout(() => $playbutton.removeClass('bg-gray').prop('disabled', false), 2500);
}
function updateVolume() {
@@ -108,4 +114,5 @@ function updateVolume() {
else console.warn("Stream is not initialized.");
}
$(document).ready(Init);
$(document).ready(Init);
window.addEventListener('load', Init, false);