mirror of
https://github.com/YuzuZensai/NekoMelody.git
synced 2026-01-30 12:32:55 +00:00
✨ feat: Current song loop feature
This commit is contained in:
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user