Beispiel #1
0
        public async void Shuffle()
        {
            try
            {
                Queue <string> allQueue = IdQueue;

                foreach (var item in videoQueue)
                {
                    allQueue.Enqueue(item.Id);
                }

                videoQueue = new Queue <YoutubeExplode.Videos.Video>();

                var Rand     = new Random();
                var NewQueue = new Queue <string>();

                foreach (var Song in allQueue.ToArray().OrderBy(x => Rand.Next()))
                {
                    NewQueue.Enqueue(Song);
                }

                IdQueue = NewQueue;

                for (int i = 0; i < 5; i++)
                {
                    videoQueue.Enqueue(await youtube.Videos.GetAsync(IdQueue.Dequeue()));
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #2
0
        public async Task Start()
        {
            try
            {
                Cancel = new CancellationTokenSource();

                while (!Cancel.IsCancellationRequested)
                {
                    try
                    {
                        Skip = new CancellationTokenSource();

                        while (videoQueue.Count == 0 && !Cancel.IsCancellationRequested)
                        {
                            await Task.Delay(10);
                        }

                        playing = videoQueue.Dequeue();

                        while (videoQueue.Count < 5)
                        {
                            if (IdQueue.Count > 0)
                            {
                                videoQueue.Enqueue(await youtube.Videos.GetAsync(IdQueue.Dequeue()));
                            }
                            else
                            {
                                break;
                            }
                        }

                        if (playing != null)
                        {
                            await channel.SendMessageAsync(embed : Embed.New(Program.Client.CurrentUser, Field.CreateFieldBuilder("now playing", $"[{playing.Title}]({playing.Url})\n{playing.Duration}"), Colors.information));
                            await PlaySong(playing);
                        }

                        playing = null;
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (Exception)
            {
            }
        }