mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-05-10 20:11:37 +02:00
Various bug fixes
This commit is contained in:
parent
15d4e251f2
commit
c058ec95fe
7 changed files with 36 additions and 35 deletions
|
@ -19,6 +19,7 @@ export default class {
|
|||
private readonly queue: Queue;
|
||||
private readonly cacheDir: string;
|
||||
private dispatcher: StreamDispatcher | null = null;
|
||||
private nowPlaying: QueuedSong | null = null;
|
||||
private playPositionInterval: NodeJS.Timeout | undefined;
|
||||
|
||||
private positionInSeconds = 0;
|
||||
|
@ -44,6 +45,7 @@ export default class {
|
|||
this.voiceConnection.disconnect();
|
||||
}
|
||||
|
||||
this.positionInSeconds = 0;
|
||||
this.voiceConnection = null;
|
||||
this.dispatcher = null;
|
||||
}
|
||||
|
@ -56,7 +58,7 @@ export default class {
|
|||
throw new Error('Not connected to a voice channel.');
|
||||
}
|
||||
|
||||
const currentSong = this.getCurrentSong();
|
||||
const currentSong = this.queue.getCurrent();
|
||||
|
||||
if (!currentSong) {
|
||||
throw new Error('No song currently playing');
|
||||
|
@ -85,26 +87,17 @@ export default class {
|
|||
throw new Error('Not connected to a voice channel.');
|
||||
}
|
||||
|
||||
const currentSong = this.getCurrentSong();
|
||||
const currentSong = this.queue.getCurrent();
|
||||
|
||||
if (!currentSong) {
|
||||
throw new Error('Queue empty.');
|
||||
}
|
||||
|
||||
// Resume from paused state
|
||||
if (this.status === STATUS.PAUSED && this.getPosition() !== 0) {
|
||||
if (this.dispatcher) {
|
||||
this.dispatcher.resume();
|
||||
this.status = STATUS.PLAYING;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!currentSong.isLive) {
|
||||
await this.seek(this.getPosition());
|
||||
return;
|
||||
}
|
||||
|
||||
// Must be livestream, continue
|
||||
if (this.status === STATUS.PAUSED && this.getPosition() !== 0 && this.dispatcher && currentSong.url === this.nowPlaying?.url) {
|
||||
this.dispatcher.resume();
|
||||
this.status = STATUS.PLAYING;
|
||||
return;
|
||||
}
|
||||
|
||||
if (await this.isCached(currentSong.url)) {
|
||||
|
@ -117,6 +110,7 @@ export default class {
|
|||
this.attachListeners();
|
||||
|
||||
this.status = STATUS.PLAYING;
|
||||
this.nowPlaying = currentSong;
|
||||
|
||||
this.startTrackingPosition();
|
||||
}
|
||||
|
@ -135,16 +129,6 @@ export default class {
|
|||
this.stopTrackingPosition();
|
||||
}
|
||||
|
||||
private getCurrentSong(): QueuedSong|null {
|
||||
const songs = this.queue.get();
|
||||
|
||||
if (songs.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return songs[0];
|
||||
}
|
||||
|
||||
private getCachedPath(url: string): string {
|
||||
return path.join(this.cacheDir, hasha(url));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue