Beispiel #1
0
        public Player()
        {
            _status  = new PlayerStatus();
            _clients = new Dictionary <string, Client>();

            // init handlers
            _youtube = new Youtube(this);
            _vlc     = new VLC(this);
            _timer   = new Timer(this);

            _currentHandler = _youtube;
        }
Beispiel #2
0
        public void SetMode(PlayerMode mode, Client client = null)
        {
            Status.Mode = mode;
            _currentHandler.Pause();
            switch (mode)
            {
            case PlayerMode.Youtube: _currentHandler = _youtube;
                break;

            case PlayerMode.Radio: _currentHandler = _vlc;
                break;
            }
            _currentHandler.Play();
        }
Beispiel #3
0
        public void HandleCommand(string commandString, Client client = null)
        {
            try
            {
                // create log entry and send them to clients and server console
                Log(commandString, client);

                // get command and its params
                string[] commandStringSplitted = commandString.Split(new[] { ":" }, StringSplitOptions.None);
                string   command         = commandStringSplitted[0];
                string   commandArgument = commandStringSplitted.Length > 1 ? commandStringSplitted[1] : "";

                // make actions based on command
                switch (command)
                {
                case "m":
                    _currentHandler.Pause();
                    switch (commandArgument)
                    {
                    case "y":
                        Status.Mode     = PlayerMode.Youtube;
                        _currentHandler = _youtube;
                        break;

                    case "r":
                        Status.Mode     = PlayerMode.Radio;
                        _currentHandler = _vlc;
                        break;
                    }
                    _currentHandler.Play();
                    break;

                case "v":
                {
                    int volumeArg;
                    if (int.TryParse(commandArgument, out volumeArg))
                    {
                        Status.Volume = volumeArg;
                        Audio.Volume  = volumeArg;
                    }
                    break;
                }

                case "w":
                    QueueSong(commandArgument, client);
                    break;

                case "r":
                    SetRadio(commandArgument, client);
                    _currentHandler.Play();
                    break;

                case "play":
                case "start":
                    Status.State = PlayerState.Playing;
                    _currentHandler.Play();
                    break;

                case "stop":
                    Status.State = PlayerState.Stopped;
                    _currentHandler.Stop();
                    break;

                case "pause":
                    Status.State = PlayerState.Paused;
                    _currentHandler.Pause();
                    break;

                case "next":
                    _currentHandler.Next();
                    _currentHandler.Play();
                    break;

                case "show ie":
                    _youtube._browser.Visible = true;
                    break;

                case "hide ie":
                    _youtube._browser.Visible = false;
                    break;

                case "register user":
                    client.Name            = commandArgument.Trim();
                    _usersNames[client.IP] = client.Name;
                    SaveUserConfig();
                    break;

                case "yer":
                    Status.YouTubeEndRadio = FindRadio(commandArgument);
                    break;

                default:
                    throw new ArgumentException(string.Format("Command {0} not available.", commandString));
                }
            }
            catch (Exception ex)
            {
            }

            // refresh clients
            Hub.RefreshClients();
        }