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:
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);
}
}