Esempio n. 1
0
 private void CreateTcp()
 {
     tcpServer = new TcpServer(Settings.GetNumber(Settings.REMOTE_CONTROL_PORT));
     tcpServer.NetworkControl += TcpServer_NetworkControl;
     tcpServer.NetworkRequest += TcpServer_NetworkRequest;
     tcpServer.Start();
 }
Esempio n. 2
0
 private void TcpServer_NetworkRequest(TcpServer source, NetworkRequestEventArgs e)
 {
     switch (e.EventId)
     {
         case NetworkRequestEvent.PlayerStatus:
             Task.Run(async () =>
             {
                 PlayerStatusMessage psm;
                 if (player != null && !player.IsDisposed && player.IsLoaded)
                 {
                     //just cut off the position and length because they SHOULD never exceed the maximum int
                     psm = new PlayerStatusMessage(e.MessageId, await player.GetIsPlayingAsync(), (int)await player.GetPositionAsync(), (int)await player.GetDurationAsync(), await player.GetBufferPercentAsync(), (byte)await player.GetVolumeAsync());
                 }
                 else
                 {
                     byte volume = (byte)Settings.GetNumber(Settings.VOLUME);
                     psm = new PlayerStatusMessage(e.MessageId, false, 0, 0, 0, volume);
                 }
                 if (source.IsRunning)
                 {
                     source.SendToClient(e.Socket, psm);
                 }
                 else
                 {
                     Logger.Log("TCP", "Trying to send PlayerStatusMessage with closed tcp server!");
                 }
             });
             break;
         case NetworkRequestEvent.EpisodeList:
             if (currentProvider != null)
             {
                 Series s = currentProvider.GetSeries();
                 foreach (List<Episode> season in s.Seasons)
                 {
                     foreach(Episode episode in season)
                     {
                         source.SendToClient(e.Socket, new EpisodeListNetworkMessage(e.MessageId, episode));
                     }
                 }
                 source.SendToClient(e.Socket, new EpisodeListNetworkMessage(e.MessageId, null)); //send last episode marker
             }
             break;
     }
 }
Esempio n. 3
0
 private void FormSettings_FormClosed(object sender, FormClosedEventArgs e)
 {
     bool shouldTcpRun = Settings.GetBool(Settings.REMOTE_CONTROL_ACTIVATED);
     int port = Settings.GetNumber(Settings.REMOTE_CONTROL_PORT);
     if (tcpServer != null)
     {
         if (shouldTcpRun)
         {
             if (!tcpServer.IsRunning || tcpServer.Port != port)
             {
                 tcpServer.Stop();
                 CreateTcp();
             }
         }
         else
         {
             tcpServer.Stop();
             tcpServer = null;
         }
     }
     else
     {
         if (shouldTcpRun)
         {
             CreateTcp();
         }
     }
 }
Esempio n. 4
0
        private void TcpServer_NetworkControl(TcpServer source, NetworkControlEventArgs e)
        {
            switch (e.EventId)  //happens always
            {
                case NetworkControlEvent.SkipStart:
                    int newSkipStartValue = e.Data.ReadInt(0);
                    numericUpDownSkipStart.Value = newSkipStartValue;
                    break;
                case NetworkControlEvent.SkipEnd:
                    int newSkipEndValue = e.Data.ReadInt(0);
                    numericUpDownSkipEnd.Value = newSkipEndValue;
                    break;
            }

            if (player != null && !player.IsDisposed && player.IsLoaded)    //player available
            {
                switch (e.EventId)
                {
                    case NetworkControlEvent.PlayPause:
                        Task.Run(async () =>
                        {
                            if (await player.GetIsPlayingAsync())
                            {
                                player.Pause();
                            }
                            else
                            {
                                player.Play();
                            }
                        });
                        break;
                    case NetworkControlEvent.Next:
                        player.Next();
                        break;
                    case NetworkControlEvent.Previous:
                        player.Previous();
                        break;
                    case NetworkControlEvent.PlayEpisode:
                        player.Play(selectedSeason, e.Data.ReadInt(0));
                        break;
                    case NetworkControlEvent.ClosePlayer:
                        player.Close();
                        break;
                    case NetworkControlEvent.SeekTo:
                        int pos = e.Data.ReadInt(0);
                        player.SetPosition(pos);
                        break;
                    case NetworkControlEvent.ToggleFullscreen:
                        player.Maximized = !player.Maximized;
                        break;
                    case NetworkControlEvent.Volume:
                        player.SetVolume(e.Data[0]);
                        break;
                }
            }
            else    //player not available
            {
                switch (e.EventId)
                {
                    case NetworkControlEvent.Volume:
                        Settings.WriteValue(Settings.VOLUME, e.Data[0]);
                        break;
                    case NetworkControlEvent.PlayEpisode:
                        player = new FormJwPlayer();
                        player.Open(currentProvider);
                        player.EpisodeChange += Player_EpisodeChange;
                        player.Play(selectedSeason, e.Data.ReadInt(0));
                        break;
                }
            }
            
        }