From 4313feaebf9a89431e400a38bfdfb629f55a5507 Mon Sep 17 00:00:00 2001 From: Yuzu Date: Sun, 18 Aug 2024 15:06:33 +0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Current=20song=20loop=20fea?= =?UTF-8?q?ture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/player/index.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/player/index.ts b/src/player/index.ts index a701eb9..8f57d7d 100644 --- a/src/player/index.ts +++ b/src/player/index.ts @@ -3,6 +3,11 @@ import { AudioInformation, Provider } from "../providers/base"; import { SeekableStream } from "../utils/SeekableStream"; import EventEmitter from "events"; +export enum LoopMode { + None, + Current, +} + export class Player { private providers: Provider[]; private currentProvider: Provider | null = null; @@ -10,6 +15,7 @@ export class Player { private playerEvent: EventEmitter = new EventEmitter(); private paused: boolean = false; private currentAudioInformation: AudioInformation | null = null; + private loopMode: LoopMode = LoopMode.None; public _stream: SeekableStream | null = null; private _skipFlag: boolean = false; @@ -61,6 +67,16 @@ export class Player { this._stream.destroy(); } + if (this.loopMode === LoopMode.Current) { + this._createStream( + this.currentAudioInformation as AudioInformation, + this.currentAudioInformation?.url as string, + 0, + true, + ); + return; + } + if (this.queue.length > 0) { const next = this.queue.shift(); if (next) { @@ -134,6 +150,14 @@ export class Player { return information; } + public setLoopMode(mode: LoopMode) { + this.loopMode = mode; + } + + public getLoopMode() { + return this.loopMode; + } + public async seek(time: number) { if (!this._stream) throw new Error("No stream to seek");