有时机器人停止播放来自YouTube的音乐

时间:2017-10-08 15:45:23

标签: c# discord discord.net

有时机器人停止播放来自YouTube的音乐,为什么以及如何解决此问题? 我知道这个问题只适用于C#中的机器人。

当机器人停止播放音乐时,我得到了这个例外:
enter image description here

代码:

public async Task LeaveAudio(IGuild guild)
{
    if (ConnectedChannels.TryRemove(guild.Id, out client))
    {
        await client.StopAsync();//line 56
    }
}

private Process CreateLinkStream(string url)
{
    Process currentsong = new Process();

    currentsong.StartInfo = new ProcessStartInfo
    {
        FileName = "cmd.exe",
        Arguments = $"/C youtube-dl.exe -o - {url} | ffmpeg -i pipe:0 -ac 2 -f s16le -ar 48100 pipe:1",
        UseShellExecute = false,
        RedirectStandardOutput = true,
        CreateNoWindow = true
    };

    currentsong.Start();
    return currentsong;
}

public async Task SendLinkAsync(IGuild guild, IMessageChannel channel, string path)
{
    if (ConnectedChannels.TryGetValue(guild.Id, out client))
    {
        cancel = new CancellationTokenSource();
        var output = CreateLinkStream(path).StandardOutput.BaseStream;
        var stream = client.CreatePCMStream(AudioApplication.Music, 128 * 1024);
        await output.CopyToAsync(stream, 81920, cancel.Token);
        await stream.FlushAsync().ConfigureAwait(false);
    }
}

0 个答案:

没有答案
相关问题