public async Task SendAudioAsync(FileInfo ffmpeg) { while (Playlist.TryDequeue(out var path)) { _songTags = IMediaTag.Parse(path); _statusEmote = _playEmote; _statusColor = Color.Green; await RefreshEmbed().ConfigureAwait(false); using (_ffmpeg = Process.Start(new ProcessStartInfo { FileName = ffmpeg.FullName, Arguments = $"-hide_banner -loglevel panic -i \"{path.FullName}\" -ac 2 -f s16le -ar 48000 pipe:1", UseShellExecute = false, //RedirectStandardInput = true, RedirectStandardOutput = true, CreateNoWindow = false })) //using (var input = _ffmpeg.StandardInput.BaseStream) using (var stream = Client.CreatePCMStream(AudioApplication.Music)) { try { await PausableCopyToAsync(_ffmpeg.StandardOutput.BaseStream, stream, 8192).ConfigureAwait(false); } catch (OperationCanceledException) { if (!_next) { Playlist.Clear(); } else { _next = false; } } finally { await stream.FlushAsync().ConfigureAwait(false); } } } _ffmpeg = null; _songTags = null; _statusEmote = _stopEmote; _statusColor = Color.Red; await RefreshEmbed().ConfigureAwait(false); }
private Task RefreshEmbed() { var emb = new EmbedBuilder { Title = "Now playing:", Description = $"{_statusEmote ?? _stopEmote} {_songTags?.Title ?? "*Stopped*"}", Color = _statusColor, Fields = { new EmbedFieldBuilder { IsInline = true, Name = "Volume:", Value = $"{(int)(_playingVolume * 101)}%" }, new EmbedFieldBuilder { IsInline = true, Name = "Next song:", Value = PeekNextSongTitle() ?? "*(None)*" } } }.Build(); return(Message.ModifyAsync(m => m.Embed = emb)); string?PeekNextSongTitle() { if (Playlist.TryPeek(out var next)) { var tags = IMediaTag.Parse(next); return(tags?.Title); } return(null); } }