Esempio n. 1
0
        /// <summary>
        /// Handle actions
        /// We'll make play/pause a toggle, just so we can ensure we support media buttons properly
        /// </summary>
        /// <param name="action"></param>
        void OnNewAction(string action, bool overrideCheck = false)
        {
            // Ignore duplicate actions within 300ms (apparently the Netflix connector has duplicate actions, I suspect it's because the Netflix connector is sending space key and this is doing the play/pause and firing an action :-( )
            if (!overrideCheck && _lastActionTime.AddMilliseconds(300) > DateTime.Now)
            {
                return;
            }

            _lastActionTime = DateTime.Now;
            _logger.Debug(string.Format("OnNewAction received {0}", action));

            switch (action)
            {
            case "ACTION_PLAY":
            case "ACTION_MUSIC_PLAY":
                if (_lastPlayPauseState == PlayPauseToggle.Play)
                {
                    OnNewAction("ACTION_PAUSE", true);
                }
                else
                {
                    _connector.Play();
                    _lastPlayPauseState = PlayPauseToggle.Play;
                }
                break;

            case "ACTION_PAUSE":
                if (_lastPlayPauseState == PlayPauseToggle.Pause)
                {
                    OnNewAction("ACTION_PLAY", true);
                }
                else
                {
                    _connector.Pause();
                    _lastPlayPauseState = PlayPauseToggle.Pause;
                }
                break;

            case "ACTION_STOP":
            case "ACTION_PREVIOUS_MENU":
                ForceQuit();
                break;

            case "ACTION_CONTEXT_MENU":     // Change the screen we're on using the context menu button
                CurrentScreen++;
                SetCurrentScreen();
                break;

            default:
                // fire the action on the connector also
                _connector.OnAction(action);
                break;
            }
        }
        /// <summary>
        /// Handle actions
        /// We'll make play/pause a toggle, just so we can ensure we support media buttons properly
        /// </summary>
        /// <param name="action"></param>
        void OnNewAction(string action, bool overrideCheck = false)
        {
            // Ignore duplicate actions within 300ms (apparently the Netflix connector has duplicate actions, I suspect it's because the Netflix connector is sending space key and this is doing the play/pause and firing an action :-( )
            if (!overrideCheck && _lastActionTime.AddMilliseconds(300) > DateTime.Now)
                return;
            
            _lastActionTime = DateTime.Now;
            _logger.Debug(string.Format("OnNewAction received {0}", action));

            switch (action)
            {
                case "ACTION_PLAY":
                case"ACTION_MUSIC_PLAY":
                    if (_lastPlayPauseState == PlayPauseToggle.Play)
                        OnNewAction("ACTION_PAUSE", true);
                    else
                    {
                        _connector.Play();
                        _lastPlayPauseState = PlayPauseToggle.Play;
                    }
                    break;
                case "ACTION_PAUSE":
                    if (_lastPlayPauseState == PlayPauseToggle.Pause)
                        OnNewAction("ACTION_PLAY", true);
                    else
                    {
                        _connector.Pause();
                        _lastPlayPauseState = PlayPauseToggle.Pause;
                    }
                    break;
                case "ACTION_STOP":
                case "ACTION_PREVIOUS_MENU":
                    ForceQuit();
                    break;
                case "ACTION_CONTEXT_MENU": // Change the screen we're on using the context menu button
                    CurrentScreen++;
                    SetCurrentScreen();
                    break;
                default:
                    // fire the action on the connector also
                    _connector.OnAction(action);
                    break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Handle actions
        /// We'll make play/pause a toggle, just so we can ensure we support media buttons properly
        /// </summary>
        /// <param name="action"></param>
        /// <param name="overrideCheck"></param>
        void OnNewAction(string action, bool overrideCheck = false)
        {
            // Ignore duplicate actions within 300ms (apparently the Netflix connector has duplicate actions, I suspect it's because the Netflix connector is sending space key and this is doing the play/pause and firing an action :-( )
            if (!overrideCheck && _lastActionTime.AddMilliseconds(300) > DateTime.Now)
                return;

            _lastActionTime = DateTime.Now;
            _logger.Debug(string.Format("OnNewAction received {0}", action));

            // Special case, command contains size arguments
            if (action.StartsWith(Constants.ACTION_WINDOWED))
            {
                SetScreenState(ScreenMode.Windowed);
                var sizeArgs = action.Replace(Constants.ACTION_WINDOWED, "").Split(',');
                if (sizeArgs.Length == 4)
                {
                    int left;
                    int top;
                    int width;
                    int height;
                    if (int.TryParse(sizeArgs[0], out left) &&
                        int.TryParse(sizeArgs[1], out top) &&
                        int.TryParse(sizeArgs[2], out width) &&
                        int.TryParse(sizeArgs[3], out height))
                    {
                        Size = new Size(width, height);
                        Location = new Point(left, top);
                        TopMost = true;
                        BringToFront();
                        _logger.Debug("ACTION_WINDOWED: Position: {0}, Size: {1}", Location, Size);
                    }
                }
                return;
            }
            switch (action)
            {
                case Constants.ACTION_PLAY:
                case Constants.ACTION_MUSIC_PLAY:
                    if (_lastPlayPauseState == PlayPauseToggle.Play)
                        OnNewAction(Constants.ACTION_PAUSE, true);
                    else
                    {
                        _connector.Play();
                        _lastPlayPauseState = PlayPauseToggle.Play;
                    }
                    break;
                case Constants.ACTION_PAUSE:
                    if (_lastPlayPauseState == PlayPauseToggle.Pause)
                        OnNewAction(Constants.ACTION_PLAY, true);
                    else
                    {
                        _connector.Pause();
                        _lastPlayPauseState = PlayPauseToggle.Pause;
                    }
                    break;
                case Constants.ACTION_STOP:
                case Constants.ACTION_PREVIOUS_MENU:
                    ForceQuit();
                    break;
                case Constants.ACTION_CONTEXT_MENU: // Change the screen we're on using the context menu button
                    CurrentScreen++;
                    SetCurrentScreen();
                    break;
                case Constants.ACTION_FULLSCREEN:
                    SetScreenState(ScreenMode.Fullscreen);
                    break;
                default:
                    // fire the action on the connector also
                    _connector.OnAction(action);
                    break;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Handle actions
        /// We'll make play/pause a toggle, just so we can ensure we support media buttons properly
        /// </summary>
        /// <param name="action"></param>
        /// <param name="overrideCheck"></param>
        void OnNewAction(string action, bool overrideCheck = false)
        {
            // Ignore duplicate actions within 300ms (apparently the Netflix connector has duplicate actions, I suspect it's because the Netflix connector is sending space key and this is doing the play/pause and firing an action :-( )
            if (!overrideCheck && _lastActionTime.AddMilliseconds(300) > DateTime.Now)
            {
                return;
            }

            _lastActionTime = DateTime.Now;
            _logger.Debug(string.Format("OnNewAction received {0}", action));

            // Special case, command contains size arguments
            if (action.StartsWith(Constants.ACTION_WINDOWED))
            {
                SetScreenState(ScreenMode.Windowed);
                var sizeArgs = action.Replace(Constants.ACTION_WINDOWED, "").Split(',');
                if (sizeArgs.Length == 4)
                {
                    int left;
                    int top;
                    int width;
                    int height;
                    if (int.TryParse(sizeArgs[0], out left) &&
                        int.TryParse(sizeArgs[1], out top) &&
                        int.TryParse(sizeArgs[2], out width) &&
                        int.TryParse(sizeArgs[3], out height))
                    {
                        Size     = new Size(width, height);
                        Location = new Point(left, top);
                        TopMost  = true;
                        BringToFront();
                        _logger.Debug("ACTION_WINDOWED: Position: {0}, Size: {1}", Location, Size);
                    }
                }
                return;
            }
            switch (action)
            {
            case Constants.ACTION_PLAY:
            case Constants.ACTION_MUSIC_PLAY:
                if (_lastPlayPauseState == PlayPauseToggle.Play)
                {
                    OnNewAction(Constants.ACTION_PAUSE, true);
                }
                else
                {
                    _connector.Play();
                    _lastPlayPauseState = PlayPauseToggle.Play;
                }
                break;

            case Constants.ACTION_PAUSE:
                if (_lastPlayPauseState == PlayPauseToggle.Pause)
                {
                    OnNewAction(Constants.ACTION_PLAY, true);
                }
                else
                {
                    _connector.Pause();
                    _lastPlayPauseState = PlayPauseToggle.Pause;
                }
                break;

            case Constants.ACTION_STOP:
            case Constants.ACTION_PREVIOUS_MENU:
                ForceQuit();
                break;

            case Constants.ACTION_CONTEXT_MENU:     // Change the screen we're on using the context menu button
                CurrentScreen++;
                SetCurrentScreen();
                break;

            case Constants.ACTION_FULLSCREEN:
                SetScreenState(ScreenMode.Fullscreen);
                break;

            default:
                // fire the action on the connector also
                _connector.OnAction(action);
                break;
            }
        }