mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
Merge pull request #154 from XuVIIJay/fix/output-side-seek
fix(audio): 网易云拖动进度条播放中断,改用输出侧 seek 兼容不支持 Range 的 CDN
This commit is contained in:
2 files changed
+5
-3
No files matched your search
@@ -55,13 +55,13 @@ describe("buildFfmpegArgs", () => {
|
|||||||
expect(idx).toBeLessThan(args.indexOf("-i")); // input options must precede -i
|
expect(idx).toBeLessThan(args.indexOf("-i")); // input options must precede -i
|
||||||
});
|
});
|
||||||
|
|
||||||
it("inserts -ss before -i when seekSeconds > 0", () => {
|
it("inserts -ss after -i when seekSeconds > 0", () => {
|
||||||
const args = buildFfmpegArgs("https://example.com/song.mp3", 42);
|
const args = buildFfmpegArgs("https://example.com/song.mp3", 42);
|
||||||
const ssIdx = args.indexOf("-ss");
|
const ssIdx = args.indexOf("-ss");
|
||||||
const iIdx = args.indexOf("-i");
|
const iIdx = args.indexOf("-i");
|
||||||
expect(ssIdx).toBeGreaterThan(-1);
|
expect(ssIdx).toBeGreaterThan(-1);
|
||||||
expect(args[ssIdx + 1]).toBe("42");
|
expect(args[ssIdx + 1]).toBe("42");
|
||||||
expect(ssIdx).toBeLessThan(iIdx);
|
expect(ssIdx).toBeGreaterThan(iIdx);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not insert -ss when seekSeconds is 0", () => {
|
it("does not insert -ss when seekSeconds is 0", () => {
|
||||||
|
|||||||
+3
-1
@@ -103,8 +103,10 @@ export function buildFfmpegArgs(url: string, seekSeconds: number): string[] {
|
|||||||
"-reconnect_on_http_error", "4xx,5xx",
|
"-reconnect_on_http_error", "4xx,5xx",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
args.push("-i", url);
|
||||||
|
// Output-side seek (after -i): works on CDNs that reject Range/keyframe seeks (NetEase music.126.net).
|
||||||
if (seekSeconds > 0) args.push("-ss", String(seekSeconds));
|
if (seekSeconds > 0) args.push("-ss", String(seekSeconds));
|
||||||
args.push("-i", url, "-f", "s16le", "-ar", "48000", "-ac", "2", "-acodec", "pcm_s16le", "-");
|
args.push("-f", "s16le", "-ar", "48000", "-ac", "2", "-acodec", "pcm_s16le", "-");
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user