fix: resolve silent voice playback on VPS and queue screenshare streams
- Call unpause() when starting a stream in DiscordPlayer to prevent getting stuck in a paused state. - Call stop() instead of pause() in VoiceController on disconnect to fully reset the player. - Add user-agent header to ffmpeg calls in MusicPlayer and Transcoder to prevent YouTube 403 Forbidden on VPS. - Add screenshare streams to the media queue when successfully started. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
279ae07745
commit
3ae7a4c6ad
@@ -86,6 +86,10 @@ export class MediaController {
|
|||||||
this.playbackToken++;
|
this.playbackToken++;
|
||||||
this.playback?.stop();
|
this.playback?.stop();
|
||||||
this.playback = null;
|
this.playback = null;
|
||||||
|
this.assertCanStartMusic();
|
||||||
|
this.queueStore.clear();
|
||||||
|
this.queueStore.add(resolved, mode, options.requestedBy);
|
||||||
|
this.queueStore.startNext();
|
||||||
return this.startScreen(resolved.source);
|
return this.startScreen(resolved.source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,6 +183,7 @@ export class MediaController {
|
|||||||
this.screenPlayback = await screenController.start(source);
|
this.screenPlayback = await screenController.start(source);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.activeMode = null;
|
this.activeMode = null;
|
||||||
|
this.queueStore.failCurrent();
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,6 +198,7 @@ export class MediaController {
|
|||||||
if (!this.screenPlayback || this.activeMode !== "screen") return;
|
if (!this.screenPlayback || this.activeMode !== "screen") return;
|
||||||
this.screenPlayback = null;
|
this.screenPlayback = null;
|
||||||
this.activeMode = null;
|
this.activeMode = null;
|
||||||
|
this.queueStore.completeCurrent();
|
||||||
this.emitState();
|
this.emitState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,10 +77,20 @@ export function createMusicPlayer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function buildFfmpegArgs(source: string): string[] {
|
export function buildFfmpegArgs(source: string): string[] {
|
||||||
return [
|
const args = [
|
||||||
"-hide_banner",
|
"-hide_banner",
|
||||||
"-loglevel",
|
"-loglevel",
|
||||||
"warning",
|
"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",
|
"-i",
|
||||||
source,
|
source,
|
||||||
"-vn",
|
"-vn",
|
||||||
@@ -93,5 +103,7 @@ export function buildFfmpegArgs(source: string): string[] {
|
|||||||
"-f",
|
"-f",
|
||||||
"s16le",
|
"s16le",
|
||||||
"pipe:1",
|
"pipe:1",
|
||||||
];
|
);
|
||||||
|
|
||||||
|
return args;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ export class DiscordPlayer {
|
|||||||
this.setResourceVolume(nextVolume);
|
this.setResourceVolume(nextVolume);
|
||||||
}
|
}
|
||||||
this.player.play(resource);
|
this.player.play(resource);
|
||||||
|
this.unpause(owner);
|
||||||
this.connection?.subscribe(this.player);
|
this.connection?.subscribe(this.player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,16 @@ export class Transcoder {
|
|||||||
"-hide_banner",
|
"-hide_banner",
|
||||||
"-loglevel",
|
"-loglevel",
|
||||||
"warning",
|
"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",
|
"-i",
|
||||||
this.source,
|
this.source,
|
||||||
"-c:v",
|
"-c:v",
|
||||||
@@ -53,8 +63,8 @@ export class Transcoder {
|
|||||||
"libopus",
|
"libopus",
|
||||||
"-f",
|
"-f",
|
||||||
"matroska",
|
"matroska",
|
||||||
"-",
|
"-"
|
||||||
];
|
);
|
||||||
|
|
||||||
const cmd = spawn("ffmpeg", args, { stdio: ["ignore", "pipe", "pipe"] });
|
const cmd = spawn("ffmpeg", args, { stdio: ["ignore", "pipe", "pipe"] });
|
||||||
const out = cmd.stdout ?? new PassThrough();
|
const out = cmd.stdout ?? new PassThrough();
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ export class VoiceController {
|
|||||||
stopRecording(this.activeGuildId);
|
stopRecording(this.activeGuildId);
|
||||||
}
|
}
|
||||||
|
|
||||||
discordPlayer.pause();
|
discordPlayer.stop();
|
||||||
this.activeGuildId = null;
|
this.activeGuildId = null;
|
||||||
this.activeChannelId = null;
|
this.activeChannelId = null;
|
||||||
this.activeChannelName = null;
|
this.activeChannelName = null;
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ describe("createMusicPlayer", () => {
|
|||||||
"-hide_banner",
|
"-hide_banner",
|
||||||
"-loglevel",
|
"-loglevel",
|
||||||
"warning",
|
"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",
|
"-i",
|
||||||
"https://example.com/song.mp3",
|
"https://example.com/song.mp3",
|
||||||
"-vn",
|
"-vn",
|
||||||
|
|||||||
Reference in New Issue
Block a user