mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 18:59:19 +00:00
Add music loop
This commit is contained in:
@@ -54,6 +54,11 @@ export class VoiceDisconnectedEvent {
|
||||
this.instance = instance;
|
||||
}
|
||||
}
|
||||
|
||||
export enum DiscordMusicPlayerLoopMode {
|
||||
None = "none",
|
||||
Current = "current"
|
||||
}
|
||||
export class DiscordMusicPlayerInstance {
|
||||
public queue: Queue;
|
||||
public player: AudioPlayer;
|
||||
@@ -61,6 +66,8 @@ export class DiscordMusicPlayerInstance {
|
||||
public voiceChannel: (VoiceChannel | StageChannel);
|
||||
public voiceConnection?: VoiceConnection;
|
||||
|
||||
public loopMode: DiscordMusicPlayerLoopMode = DiscordMusicPlayerLoopMode.None;
|
||||
|
||||
public readonly events: EventEmitter;
|
||||
|
||||
constructor({ voiceChannel }: { voiceChannel: (VoiceChannel | StageChannel) }) {
|
||||
@@ -77,12 +84,21 @@ export class DiscordMusicPlayerInstance {
|
||||
this.player.on(AudioPlayerStatus.Idle, async (oldStage, newStage) => {
|
||||
//The player stopped
|
||||
if (newStage.status === AudioPlayerStatus.Idle && oldStage.status !== AudioPlayerStatus.Idle) {
|
||||
|
||||
// Loop mode is set to current song
|
||||
if (this.loopMode === DiscordMusicPlayerLoopMode.Current) {
|
||||
this.playTrack(this.queue.track[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
// There are more songs in the queue, remove finished song and play the next one
|
||||
if (this.queue.track.length !== 0) {
|
||||
this.queue.track.shift();
|
||||
if (this.queue.track.length > 0) {
|
||||
this.playTrack(this.queue.track[0]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@@ -196,6 +212,14 @@ export class DiscordMusicPlayerInstance {
|
||||
}
|
||||
}
|
||||
|
||||
public setLoopMode(mode: DiscordMusicPlayerLoopMode) {
|
||||
this.loopMode = mode;
|
||||
}
|
||||
|
||||
public getLoopMode() {
|
||||
return this.loopMode;
|
||||
}
|
||||
|
||||
public async destroy() {
|
||||
await this.leaveVoiceChannel();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user