示例#1
0
 public int GetPacketQueueCount()
 {
     try
     {
         var         pq   = Vnc.GetType().GetField("<PacketQueue>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Vnc);
         ICollection list = pq as ICollection;
         return(list.Count);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(10);
     }
 }
示例#2
0
 private async void VncWindow_Loaded(object sender, RoutedEventArgs e)
 {
     if (DestinationMonitor.Number < System.Windows.Forms.Screen.AllScreens.Length)
     {
         var screen = System.Windows.Forms.Screen.AllScreens[DestinationMonitor.Number];
         var area   = screen.WorkingArea;
         Top  = area.Top;
         Left = area.Left;
     }
     else
     {
         MessageBox.Show($"You don't have a screen with id {DestinationMonitor}");
     }
     WindowState = WindowState.Maximized;
     if (Monitor.Connection != null)
     {
         await Vnc.Attach(Monitor.Connection, Monitor.VisualOffset);
     }
 }
示例#3
0
 /// <summary>
 /// Throws a <see cref="VncException"/> if a specific condition is not met.
 /// </summary>
 /// <param name="condition">
 /// The condition which should be met.
 /// </param>
 /// <param name="message">
 /// A <see cref="string"/> that describes the error.
 /// </param>
 /// <param name="reason">
 /// A <see cref="VncFailureReason"/> that describes the error.
 /// </param>
 public static void Require(bool condition, string message, Vnc.VncFailureReason reason)
 {
     if (!condition)
     {
         throw new Vnc.VncException(message, reason);
     }
 }
示例#4
0
 private async void VncWindow_Closed(object?sender, EventArgs e)
 {
     CancelSource.Cancel();
     await Vnc.Stop();
 }
示例#5
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);
            }
        }