1

Sometimes the bot stop playing the music from YouTube, why and how I can fix this? I know cause this problem is just for the bots in C#.

And i get this exception when the bot stop playing the music:
enter image description here

Code:

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);
    }
}
Green Falcon
  • 818
  • 3
  • 17
  • 48
  • Take a look at this : https://stackoverflow.com/questions/29179848/httpclient-a-task-was-cancelled – Unknown Oct 08 '17 at 17:14
  • @Unknown , One more thing, the error is just if i use youtube-dl to play the music, if will play the music with ffmpeg from my PC, i don't have this problem. –  Oct 08 '17 at 19:59

0 Answers0