node.js - 检查是否在机器人上播放音乐(从 youtube 流式传输)
问题描述
我刚刚创建了一个工作队列命令,但现在我坚持编辑播放命令
我试图让它如果正在播放音乐,播放命令只会将查询推送到队列并等待音乐完成播放然后转移队列以播放下一个。
我坚持如何检查机器人是否仍在从互联网上播放音乐。
//push function, stream and streamOptions is above from here
if (/*check whether a music is playing = false*/) {
function dispatcher() {
connection.playStream(stream, streamOptions)
dispatcher.on('end', function () {
lst.shiftlist(); //shift the queue
if (lst.urllist[0]/*check if queue[0] contains*/) {
dispatcher();
}
else {
message.channel.send('Queue empty!');
return;
}
})
}
}
else if (/*check whether a music is playing = true*/) {
message.channel.send('Added to queue!')
console.log(url)
}
是否可以检查机器人是否仍在播放流?还是我可以使用其他任何方法来解决这个问题?
解决方案
在我的脑海中,最简单的方法是在音乐开始播放时切换某种状态,并在调度程序结束事件触发时将其关闭。就像是:
var playing = false
if (/*check whether a music is playing = false*/) {
function dispatcher() {
connection.playStream(stream, streamOptions)
playing = true
dispatcher.on('end', function () {
lst.shiftlist(); //shift the queue
if (lst.urllist[0]/*check if queue[0] contains*/) {
dispatcher();
}
else {
playing = false
message.channel.send('Queue empty!');
return;
}
})
}
}
else if (/*check whether a music is playing = true*/) {
message.channel.send('Added to queue!')
console.log(url)
}
推荐阅读
- ajax - 具有代理扩展 POST 请求的 Shopify 应用程序不起作用
- ios - 如何在领域 swift 中使用 LIKE/CONTAINS 查询双值
- python - 来自 dict 的 Pandas 数据框,为什么?
- r - 我怎样才能转换这个表?
- javascript - 切换 Vuetify 导航抽屉 v-modeled 到 Vuex 变量
- reactjs - 反应函数、ImagePicker 和 ActionSheet 中的无效挂钩调用
- java - 将 JSON 数组解组为对象,同时忽略空值
- excel - 通过excel将unix时间更改为日期时间时出错
- python-3.x - 如何解决“长度”参数应该是一维 CPU int64?
- css - 如何将元素的高度与网格的项目高度分离