mirror of
https://github.com/YuzuZensai/NekoMelody.git
synced 2026-01-31 14:57:58 +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 { SeekableStream } from "../utils/SeekableStream";
|
||||||
import EventEmitter from "events";
|
import EventEmitter from "events";
|
||||||
|
|
||||||
|
export enum LoopMode {
|
||||||
|
None,
|
||||||
|
Current,
|
||||||
|
}
|
||||||
|
|
||||||
export class Player {
|
export class Player {
|
||||||
private providers: Provider[];
|
private providers: Provider[];
|
||||||
private currentProvider: Provider | null = null;
|
private currentProvider: Provider | null = null;
|
||||||
@@ -10,6 +15,7 @@ export class Player {
|
|||||||
private playerEvent: EventEmitter = new EventEmitter();
|
private playerEvent: EventEmitter = new EventEmitter();
|
||||||
private paused: boolean = false;
|
private paused: boolean = false;
|
||||||
private currentAudioInformation: AudioInformation | null = null;
|
private currentAudioInformation: AudioInformation | null = null;
|
||||||
|
private loopMode: LoopMode = LoopMode.None;
|
||||||
|
|
||||||
public _stream: SeekableStream | null = null;
|
public _stream: SeekableStream | null = null;
|
||||||
private _skipFlag: boolean = false;
|
private _skipFlag: boolean = false;
|
||||||
@@ -61,6 +67,16 @@ export class Player {
|
|||||||
this._stream.destroy();
|
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) {
|
if (this.queue.length > 0) {
|
||||||
const next = this.queue.shift();
|
const next = this.queue.shift();
|
||||||
if (next) {
|
if (next) {
|
||||||
@@ -134,6 +150,14 @@ export class Player {
|
|||||||
return information;
|
return information;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setLoopMode(mode: LoopMode) {
|
||||||
|
this.loopMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getLoopMode() {
|
||||||
|
return this.loopMode;
|
||||||
|
}
|
||||||
|
|
||||||
public async seek(time: number) {
|
public async seek(time: number) {
|
||||||
if (!this._stream) throw new Error("No stream to seek");
|
if (!this._stream) throw new Error("No stream to seek");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user