From 3f00ec31b773f9e8a93e83963ad2d75f87b075ea Mon Sep 17 00:00:00 2001 From: Yuzu Date: Fri, 5 Jul 2024 10:50:22 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Queue=20not=20playing=20n?= =?UTF-8?q?ext=20song?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- src/player/index.ts | 6 ++++++ src/providers/yt-dlp.ts | 15 +++++++++++++-- src/utils/SeekableStream.ts | 7 +++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e5f0330..6c8a3bd 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "", "scripts": { "build": "tsup ./src", - "example:test": "tsup ./src && tsx ./example/test.ts", + "example:discord": "tsup ./src && tsx ./example/discord.ts", + "example:speaker": "tsup ./src && tsx ./example/speaker.ts", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], diff --git a/src/player/index.ts b/src/player/index.ts index c97020c..bfbd429 100644 --- a/src/player/index.ts +++ b/src/player/index.ts @@ -49,6 +49,12 @@ export class Player { this.playerEvent.emit("play", information); } + public startCurrentStream() { + if (this._stream) { + this._stream.start(); + } + } + public endCurrentStream() { if (this._stream) { this._stream.destroy(); diff --git a/src/providers/yt-dlp.ts b/src/providers/yt-dlp.ts index d383615..0bcf02d 100644 --- a/src/providers/yt-dlp.ts +++ b/src/providers/yt-dlp.ts @@ -6,8 +6,19 @@ export class YtDlpProvider extends Provider { public ytDlpWrap = new YTDlpWrap(); public canPlay(url: string) { - // TODO: Implement this - return true; + return this.checkUrl(url); + } + + private checkUrl(url: string) { + // https://www.youtube.com/watch?v= + // https://youtu.be/ + if ( + url.startsWith("https://www.youtube.com/watch?v=") || + url.startsWith("https://youtu.be/") + ) + return true; + + return false; } public async getInformation(url: string) { diff --git a/src/utils/SeekableStream.ts b/src/utils/SeekableStream.ts index b7b1980..c4f2afc 100644 --- a/src/utils/SeekableStream.ts +++ b/src/utils/SeekableStream.ts @@ -19,6 +19,7 @@ export class SeekableStream { private firstTick: boolean = true; private destroyed: boolean = false; private event: EventEmitter = new EventEmitter(); + private started: boolean = false; private bytesReceived: number = 0; private bytesRead: number = 0; @@ -54,6 +55,10 @@ export class SeekableStream { //if (seekTime !== 0) this.seek(); } + public start() { + this.started = true; + } + private async tick(seekTime?: number) { if (this.destroyed) { console.debug( @@ -152,6 +157,8 @@ export class SeekableStream { return; } + if (!this.started) return; + const isBufferSufficient = this.stream.readableLength >= this.bytesPerRequestLimit;