javascript - ffmpeg 的问题(不加载歌曲?) - ffmpeg 流:写 EPIPE
问题描述
问题:对于我通过 discord.js 模块播放的一些歌曲StreamDispatcher
(似乎是开头有静音的歌曲),调度程序几乎会立即完成并抛出错误。我使用 ffmpeg-static 模块。
从我所见,这是我从调用调度程序的“调试”和“错误”事件中收到的两个错误
Error: ffmpeg stream: write EPIPE
Error [ERR_STREAM_DESTROYED]: ffmpeg stream: Cannot call write after a stream was destroyed
可重现的代码示例(需要 ytdl-core):
/**
* @param {Discord.VoiceConnection} connection
* @param {String} url
*/
async function run(connection, url) // assuming these two variables aren't null
{
const video = ytdl(url, { highWaterMark: 5242880 });
video.on("error", (err) => console.log(err));
let dispatcher = connection.play(video);
dispatcher.on("finish", () => console.log("finished"));
break;
}
// recommended url: https://www.youtube.com/watch?v=Auk1oVI2Icw
// (this is one i've been using to test this issue)
我项目的原始代码加上指导的一些评论:
async play() // this is my function for playing music on the bot
{
if (this.queue.length === 0) return;
if (!this.guild.me.voice || !this.guild.me.voice.channel) return;
let connection = this.guild.me.voice.connection;
if (!connection) return;
if (connection.dispatcher) return;
let track = this.queue[0];
let channel = this.guild.channels.cache.get(track.channelID);
switch (track.type)
{
//case "soundcloud" omitted
case "youtube":
{
const video = ytdl(track.url, { highWaterMark: 5242880 });
video.on("error", (err) => console.log(err));
channel.send(`playing: **${track.name}** // requester: **${track.requester.tag}**`);
let dispatcher = connection.play(video); // dispatcher will begin
dispatcher.setVolume(this.volume);
dispatcher.on("finish", () => this.finish()); // almost immediately the following will be called
// fyi: there isn't anything special in the function called, just some code to shift the queue
break;
}
}
}
细节:
- discord.js 版本:12.4.1
- node.js 版本:v12.18.3
- 操作系统:Windows 10
解决方案
推荐阅读
- magento - 如何将一个对象映射到 magento2 数据模型数组?
- node.js - 如何运行 MERN 应用程序
- java - Slf4j log.debug 在函数 bean 中抛出 NPE
- amazon-web-services - 在 lambda 环境变量中存储 Web 服务 URL
- xaml - 禁用标签上的剪辑
- python - 使用 SQLalchemy 从 Docker 容器连接到外部 MySQL 数据库
- c++ - std::reverse_iterator 是否适用于适应范围?
- java - Java.persistance.rollback.rollback 异常
- android - 为什么在 Java 错误中不推荐使用底部导航?
- spring-boot - 如何摆脱为id“null”映射的No PasswordEncoder