diff --git a/src/media/mediaController.ts b/src/media/mediaController.ts index 191a626..bec8b3f 100644 --- a/src/media/mediaController.ts +++ b/src/media/mediaController.ts @@ -86,6 +86,10 @@ export class MediaController { this.playbackToken++; this.playback?.stop(); this.playback = null; + this.assertCanStartMusic(); + this.queueStore.clear(); + this.queueStore.add(resolved, mode, options.requestedBy); + this.queueStore.startNext(); return this.startScreen(resolved.source); } @@ -179,6 +183,7 @@ export class MediaController { this.screenPlayback = await screenController.start(source); } catch (error) { this.activeMode = null; + this.queueStore.failCurrent(); throw error; } @@ -193,6 +198,7 @@ export class MediaController { if (!this.screenPlayback || this.activeMode !== "screen") return; this.screenPlayback = null; this.activeMode = null; + this.queueStore.completeCurrent(); this.emitState(); } diff --git a/src/media/musicPlayer.ts b/src/media/musicPlayer.ts index 21d0d0e..e5c954e 100644 --- a/src/media/musicPlayer.ts +++ b/src/media/musicPlayer.ts @@ -77,10 +77,20 @@ export function createMusicPlayer( } export function buildFfmpegArgs(source: string): string[] { - return [ + const args = [ "-hide_banner", "-loglevel", "warning", + ]; + + if (source.startsWith("http://") || source.startsWith("https://")) { + args.push( + "-user_agent", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" + ); + } + + args.push( "-i", source, "-vn", @@ -93,5 +103,7 @@ export function buildFfmpegArgs(source: string): string[] { "-f", "s16le", "pipe:1", - ]; + ); + + return args; } diff --git a/src/player.ts b/src/player.ts index 94858e3..66afedb 100644 --- a/src/player.ts +++ b/src/player.ts @@ -76,6 +76,7 @@ export class DiscordPlayer { this.setResourceVolume(nextVolume); } this.player.play(resource); + this.unpause(owner); this.connection?.subscribe(this.player); } diff --git a/src/streaming/transcoder.ts b/src/streaming/transcoder.ts index 50bdfec..91dddf8 100644 --- a/src/streaming/transcoder.ts +++ b/src/streaming/transcoder.ts @@ -35,6 +35,16 @@ export class Transcoder { "-hide_banner", "-loglevel", "warning", + ]; + + if (this.source.startsWith("http://") || this.source.startsWith("https://")) { + args.push( + "-user_agent", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" + ); + } + + args.push( "-i", this.source, "-c:v", @@ -53,8 +63,8 @@ export class Transcoder { "libopus", "-f", "matroska", - "-", - ]; + "-" + ); const cmd = spawn("ffmpeg", args, { stdio: ["ignore", "pipe", "pipe"] }); const out = cmd.stdout ?? new PassThrough(); diff --git a/src/voiceController.ts b/src/voiceController.ts index ee2b95f..20e66c0 100644 --- a/src/voiceController.ts +++ b/src/voiceController.ts @@ -159,7 +159,7 @@ export class VoiceController { stopRecording(this.activeGuildId); } - discordPlayer.pause(); + discordPlayer.stop(); this.activeGuildId = null; this.activeChannelId = null; this.activeChannelName = null; diff --git a/tests/media/musicPlayer.test.ts b/tests/media/musicPlayer.test.ts index 8629555..245e4a5 100644 --- a/tests/media/musicPlayer.test.ts +++ b/tests/media/musicPlayer.test.ts @@ -56,6 +56,8 @@ describe("createMusicPlayer", () => { "-hide_banner", "-loglevel", "warning", + "-user_agent", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36", "-i", "https://example.com/song.mp3", "-vn",