This commit is contained in:
2026-04-03 12:12:20 +02:00
parent b462a0640c
commit 537a680073
+6 -3
View File
@@ -10,8 +10,8 @@ class WebSocketAudioPlayer {
} }
_trimBuffer() { _trimBuffer() {
if (!this.sourceBuffer.updating && this.audio.currentTime > 5) { if (!this.sourceBuffer.updating && this.audio.currentTime > 1) {
this.sourceBuffer.remove(0, this.audio.currentTime - 2); this.sourceBuffer.remove(0, this.audio.currentTime - 0.5);
} }
} }
@@ -22,7 +22,10 @@ class WebSocketAudioPlayer {
this.mediaSource.addEventListener('sourceopen', () => { this.mediaSource.addEventListener('sourceopen', () => {
this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/mpeg'); this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/mpeg');
this.sourceBuffer.addEventListener('updateend', () => this._appendNext()); this.sourceBuffer.addEventListener('updateend', () => {
this._appendNext();
this._trimBuffer();
});
this.ws = new WebSocket(this.url); this.ws = new WebSocket(this.url);
this.ws.binaryType = 'arraybuffer'; this.ws.binaryType = 'arraybuffer';