Example #1
0
        private void OutAndInQueen(string CombText)
        {
            if (CombText == "")
            {
                return;
            }
            int _index = CombText.IndexOf('-');

            if (_index == -1)
            {
                return;
            }
            string TypeStr       = CombText.Substring(0, CombText.IndexOf('-'));
            int    channelNumber = Convert.ToInt32(CombText.Substring(_index + 1, CombText.Length - _index - 1));

            int TIndex = UsedChannel.FindIndex(m => (m.ChannelID == channelNumber) & (m.ChannelType == TypeStr));

            if (TIndex == -1)
            {
                return;
            }

            noUserChannel.Add(UsedChannel[TIndex]);
            UsedChannel.RemoveAt(TIndex);
            AddComb();
        }
Example #2
0
        public async Task PlayCurrentSong()
        {
            try
            {
                Console.WriteLine(CurrentSong.Position);
                Console.WriteLine(CurrentSong.DBTrackInfo.Title);
                Console.WriteLine(CurrentSongServiceResult.Title);

                var tx = Vnc.GetTransmitStream();
                //If the next songs is from a slow Service, it sends an alert that the buffering isnt ready yet
                if (CurrentSongServiceResult.Slow &&
                    CurrentSongServiceResult.CacheStatus == CacheStatus.Rendering)
                {
                    await UsedChannel.SendMessageAsync("Slow service, please wait a bit while we buffer for smooth playback");
                }

                //Start caching if it wasnt already
                if (CurrentSongServiceResult.PCMQueue == null &&
                    CurrentSongServiceResult.FillCacheTask == null)
                {
                    CurrentSongServiceResult.StartCaching();
                }

                //Wait until the the slow Serice is ready to Play (PlayReady wau)
                while (CurrentSongServiceResult.CacheStatus != CacheStatus.PlayReady &&
                       CurrentSongServiceResult.Slow)
                {
                    await Task.Delay(100);
                }

                //More of a non slow thing, wait until there is actually something cached
                while (CurrentSongServiceResult.PCMQueue == null)
                {
                    await Task.Delay(100);
                }

                var currentPCMCache = CurrentSongServiceResult.PCMQueue;

                //The main fun
                while (CurrentSongServiceResult.CacheStatus != CacheStatus.Cached ||
                       currentPCMCache.Count > 0)
                {
                    //See if there is a packet ready (just see, not take)
                    var hasPacket = currentPCMCache.TryPeek(out var none);

                    //If its paused OR THE PACKET QUEUE INTERNALLY OF DSHARPPLUS or there is no packet ready, we skip a cycle

                    if (!hasPacket ||
                        GetPacketQueueCount() > 50 ||
                        Playstate == Playstate.Paused)
                    {
                        await Task.Delay(3);

                        continue;
                    }

                    //actually take the first packet now
                    currentPCMCache.TryDequeue(out var packet);

                    //This is to see how far we have advanced into the song yet
                    if (!CurrentSongServiceResult.CurrentPosition.IsRunning)
                    {
                        CurrentSongServiceResult.CurrentPosition.Start();
                    }

                    //Write to the VoiceStream, try/catch cause sometimes it can oof, then its better to skip a bit than fail as a whole
                    try
                    {
                        await packet.CopyToAsync(tx, 3840);
                    }
                    catch { Console.WriteLine("wau"); }
                    await packet.DisposeAsync();
                }
                //Get rid of stuff and pause
                CurrentSongServiceResult.Dispose();
                CurrentSongServiceResult.CurrentPosition.Stop();
                //Clear everything

                await tx.FlushAsync();

                await Vnc.WaitForPlaybackFinishAsync();

                //Logic here to not delete the first song but the one that was played, this might be not the right way

                await DbContext.DeleteFromGuildQueue(Guild.Id, CurrentSong.Position);

                Playstate   = Playstate.NotPlaying;
                LastSong    = CurrentSong;
                CurrentSong = NextSong;
                CurrentSongServiceResult = NextSongServiceResult;

                //If there#s still songs in queue, start the playing process again
                if (await DbContext.GetGuildQueueCount(Guild.Id) != 0)
                {
                    await PreparePlayback();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }