javascript - 如何播放 .m4s 文件。并将它们转换为 Discord Bot 的二进制流
问题描述
我想下载 BBC radio 2 并将其流式传输到 discord 服务器。每个请求都是https://as-dash-uk-live.akamaized.net/pool_904/live/uk/bbc_radio_two/bbc_radio_two.isml/dash/bbc_radio_two-audio=320000-250636302.m4s但是时间戳会改变,他们定期删除内容。我还找到了一个 .dash 文件https://as-dash-uk-live.akamaized.net/pool_904/live/uk/bbc_radio_two/bbc_radio_two.isml/dash/bbc_radio_two-audio=320000.dash这似乎是请求. 但是我找不到如何通过不和谐机器人将其发送到不和谐服务器。我的代码是
const axios = require('axios')
module.exports = {
play: async function (guild,message) {
const serverQueue = {};
const voiceChannel = message.member.voice.channel
serverQueue.connection = await voiceChannel.join();
plays(guild)
async function plays(guild) {
let data1 = new Date(1353439725);
let data2 = new Date(Date.now()/1000);
console.log(`https://as-dash-uk-live.akamaized.net/pool_904/live/uk/bbc_radio_two/bbc_radio_two.isml/dash/bbc_radio_two-audio=320000-${Math.floor((data2 - data1))-4000}.m4s`)
const dispatcher = serverQueue.connection.play((await axios.get(`https://as-dash-uk-live.akamaized.net/pool_904/live/uk/bbc_radio_two/bbc_radio_two.isml/dash/bbc_radio_two-audio=320000-${Math.floor((data2 - data1))-4000}.m4s`)).data)
.on('finish', () => {
console.log('Music ended!');
plays(guild);
return
})
.on('error', error => {
console.error(error);
plays(guild);
return
});
dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
}
}
}
但是没有音频播放,并且总是调用音频结束事件。我真的很愚蠢还是有办法做到这一点。
解决方案
推荐阅读
- python - Is there a faster way to uniformly format first- and surnames on a pandas dataframe?
- unit-testing - Specify individual header files for CMake instead of full directory
- c# - How to properly add new item to ObservableCollection from another thread?
- c# - Explicit cast required for Enumerable.Empty
- keras - Keras 自动编码器输出跳到零
- r - bca.ci 中的错误(boot.out,conf,index[1L],L = L,t = to,t0 = t0.o,:估计调整“w”是无限的
- .htaccess - 子域重定向到外部 url 路径并保留子域的名称
- java - 针对特定的 Micronaut WebSocket 连接
- android - Display emojis with skin color variation in a textfield via unicode
- google-apps-script - ConvertApi 和 Google Script:我有时会收到“合并 pdf 时出现错误 500”,但并非总是如此