播放到一半时,音频会突然暂停,并显示
AudioPlayerError: aborted
我见过 bug 问题here(GitHub),但直到 2024 年才有人提出解决方案
use ytdl
const stream = ytdl(this.queue[guildID][0].url)
use play-dl
const play_stream = await play.stream(this.queue[guildID][0].url, {
discordPlayerCompatibility: true,
})
当我使用时,这两个东西都会起作用
const resource = createAudioResource(play_stream.stream, {
inputType: StreamType.WebmOpus
});
途中突然暂停播放 但如果我尝试
const outputStream = fs.createWriteStream('audio.mp3');
play_stream.stream.pipe(outputStream);
outputStream.on('finish', () => {
console.log('The audio data has been successfully saved to the file.');
});
很快就会下载完成,这说明是缓存问题。
这对我来说看起来很奇怪
discordPlayerCompatibility: true,
discordPlayerCompatibility仅在您使用discord-player(这是它自己的库)时才有效,如果您使用discord.js/voice则不需要
我用这个代替,它应该可以工作
const play_stream = await play.stream(this.queue[guildID][0].url);
let resource = createAudioResource(play_stream.stream, {
inputType: stream.type,
});