Esempio n. 1
0
        private async void ProcessQueue()
        {
            while (await _songQueue.OutputAvailableAsync())
            {
                while (!_isPlaying)
                {
                    Log.Information("Waiting for songs");
                    NowPlaying = await _songQueue.ReceiveAsync();

                    _concurrentQueue.TryDequeue(out _);
                    _isPlaying = true;
                    try
                    {
                        if (_messageChannel != null)
                        {
                            await _messageChannel?.SendMessageAsync(
                                $"Now playing **{NowPlaying.Title}** | `{NowPlaying.DurationString}` | requested by {NowPlaying.Requester} | {NowPlaying.Url}");
                        }

                        Log.Information("Connecting to voice channel");
                        using (var audioClient = await _voiceChannel.ConnectAsync())
                        {
                            Log.Information("Connected!");
                            await _audioPlaybackService.SendAsync(audioClient, NowPlaying.Uri, NowPlaying.Speed);
                        }

                        NowPlaying.OnPostPlay();
                    }
                    catch (Exception e)
                    {
                        Log.Information($"Error while playing song: {e}");
                    }
                    finally
                    {
                        _isPlaying = false;
                    }
                }
            }
        }