首页 > 解决方案 > 如何播放 .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);
        }
    }
}

但是没有音频播放,并且总是调用音频结束事件。我真的很愚蠢还是有办法做到这一点。

标签: javascriptvideoffmpegdiscord.jsmpeg-dash

解决方案


推荐阅读