示例#1
0
        /// <summary>
        /// With the Amazon player it seems that setting it to full screen (_enableFullWindowPlaybackMode) it makes the Silverlight control always take focus
        /// This means that when space bar is pressed to pause it fires in the Silverlight control before the browser host causing a double press
        /// To get around this I've added a dummy control to the page which will take focus after every action to prevent Silverlight getting the event
        /// </summary>
        /// <param name="keyStrokeToSend"></param>
        private void SendKeyToControl(string keyStrokeToSend)
        {
            var isHtml5 = IsHtml5Player;

            if (!isHtml5)
            {
                if (Browser.Document.GetElementById("dummyFocusControl") == null)
                {
                    //InvokeScript("$('#player_object').attr('height','99%');");
                    var newCtl = "$('<input  type=\"text\" id=\"dummyFocusControl\" style=\"width: 1px; height: 1%;opacity:0;color: transparent;\"/>')";
                    InvokeScript("$('#player_container').append(" + newCtl + ");");
                }
                var form = Browser.FindForm();
                Cursor.Position = new System.Drawing.Point(form.Left + 50, form.Top + 50);
                Application.DoEvents();
                CursorHelper.DoLeftMouseClick();
                Application.DoEvents();
                SendKeys.Send(keyStrokeToSend);
                Application.DoEvents();
            }
            else
            {
                SetTopMostActivate();
                SendKeys.SendWait(keyStrokeToSend);
            }

            if (!isHtml5)
            {
                InvokeScript("$('#dummyFocusControl').focus()");
            }
        }
        public override EventResult BrowserDocumentComplete()
        {
            MessageHandler.Info("Url: {0}, login: {1}, clicked: {2}, maximized: {3}", Url, login.ToString(), clicked.ToString(), maximized.ToString());
            if (login)
            {
                if (Url == "about:blank")
                {
                    login = false;
                    ProcessComplete.Finished = true;
                    ProcessComplete.Success = true;

                }
                else if (clicked && Url != loginUrl)
                {
                    login = false;
                    ProcessComplete.Finished = true;
                    ProcessComplete.Success = true;
                }
                else
                {
                    InvokeScript("document.getElementById('login-email').value = '" + username + "';");
                    InvokeScript("document.getElementById('login-password').value = '" + password + "';");
                    InvokeScript("document.getElementById('remember-me-checkbox').checked = false;");
                    InvokeScript("setTimeout(\"document.getElementsByClassName('button-submit')[0].click()\", 2000);");
                    clicked = true;
                }
            }
            else
            {
                InvokeScript("setTimeout(\"document.getElementsByClassName('play-button')[0].click()\", 2000);");
                System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
                timer.Tick += (object sender, EventArgs e) =>
                {
                    if (_showLoading) HideLoading();
                    if (!maximized)
                    {
                        maximized = true;
                        //Workaround for keeping maximized flashplayer on top
                        Browser.FindForm().Activated += FormActivated;
                        Cursor.Position = new System.Drawing.Point(Browser.FindForm().Location.X + 20, Browser.Location.Y + 200);
                        Application.DoEvents();
                        Thread.Sleep(1000);
                        //Click only once
                        CursorHelper.DoLeftMouseClick();
                        Application.DoEvents();
                        Thread.Sleep(500);
                    }
                    System.Windows.Forms.SendKeys.Send("f");
                    timer.Stop();
                    timer.Dispose();
                };

                timer.Interval = 4500;
                timer.Start();
                ProcessComplete.Finished = true;
                ProcessComplete.Success = true;

            }
            return EventResult.Complete();
        }
        public override void OnAction(string actionEnumName)
        {
            if (_currentState != State.Playing || _isUsingMouse || Browser.Document == null || Browser.Document.Body == null)
            {
                return;
            }

            if (actionEnumName == "ACTION_NEXT_SUBTITLE" || actionEnumName == "ACTION_SHOW_INFO")
            {
                _isUsingMouse = true;
                int w       = Browser.FindForm().Right;
                int h       = Browser.FindForm().Bottom;
                int subPosX = w - _xOffset;
                int subPosY = h - _yOffset;
                Cursor.Position = new System.Drawing.Point(subPosX, h - 350);
                Application.DoEvents();
                int moveOffset = 2;
                //Move around the mouse...
                for (int i = 0; i < 20; i++)
                {
                    moveOffset     *= -1;
                    Cursor.Position = new System.Drawing.Point(subPosX, subPosY + moveOffset);
                    Application.DoEvents();
                    Thread.Sleep(50);
                }
                Cursor.Position = new System.Drawing.Point(subPosX, h - SubtitleOffset);
                Application.DoEvents();
                CursorHelper.DoLeftMouseClick();
                Application.DoEvents();
                _isUsingMouse = false;
            }
        }
 private void SendKeyToBrowser(string key)
 {
     Cursor.Position = new System.Drawing.Point(Browser.FindForm().Location.X + 300, Browser.Location.Y + 300);
     Application.DoEvents();
     CursorHelper.DoLeftMouseClick();
     Application.DoEvents();
     System.Windows.Forms.SendKeys.Send(key);
 }
示例#5
0
        private void Click()
        {
            var frm = Browser.FindForm();

            Cursor.Position = new System.Drawing.Point(frm.Location.X + frm.Width / 2, frm.Location.Y + frm.Height / 2);
            Application.DoEvents();
            CursorHelper.DoLeftMouseClick();
            Application.DoEvents();
        }
        /// <summary>
        /// Find the play/pause button and click it
        /// </summary>
        /// <returns></returns>
        private EventResult DoPlayOrPause()
        {
            if (DateTime.Now < _lastPlayClick.AddMilliseconds(500))
            {
                return(EventResult.Complete());
            }

            CursorHelper.MoveMouseTo(Browser.FindForm().Left + (Browser.FindForm().Width / 2) + 50, Browser.FindForm().Top + (Browser.FindForm().Height / 2));
            CursorHelper.DoLeftMouseClick();
            CursorHelper.MoveMouseTo(0, 0);
            _lastPlayClick = DateTime.Now;
            return(EventResult.Complete());
        }
 private EventResult PlayPause()
 {
     if (_currentState != State.Playing || _isUsingMouse || Browser.Document == null || Browser.Document.Body == null)
     {
         return(EventResult.Complete());
     }
     _isUsingMouse   = true;
     Cursor.Position = new System.Drawing.Point(Browser.FindForm().Right - _xOffset, Browser.FindForm().Bottom - 350);
     Application.DoEvents();
     CursorHelper.DoLeftMouseClick();
     Application.DoEvents();
     //To show sub -language
     Cursor.Position = new System.Drawing.Point(Browser.FindForm().Right - _xOffset, Browser.FindForm().Bottom - _yOffset);
     Application.DoEvents();
     _isUsingMouse = false;
     return(EventResult.Complete());
 }
示例#8
0
 private EventResult PlayPause()
 {
     if (maximized)
     {
         Cursor.Position = new System.Drawing.Point(Browser.FindForm().Left + 100, Browser.FindForm().Bottom - 100);
         Application.DoEvents();
         Cursor.Position = new System.Drawing.Point(Browser.FindForm().Left + 35, Browser.FindForm().Bottom - 35);
         Application.DoEvents();
         CursorHelper.DoLeftMouseClick();
         Application.DoEvents();
         Cursor.Position = new System.Drawing.Point(Browser.FindForm().Left + 100, Browser.FindForm().Bottom - 100);
         Application.DoEvents();
         InvokeScript("document.getElementById('player').focus();"); //Prevent play/pause problem
         Application.DoEvents();
     }
     return(EventResult.Complete());
 }
示例#9
0
        public override EventResult BrowserDocumentComplete()
        {
            MessageHandler.Info("Url: {0}, login: {1}, clicked: {2}, maximized: {3}", Url, login.ToString(), clicked.ToString(), maximized.ToString());
            if (login)
            {
                if (refreshed)
                {
                    login = false;
                    ProcessComplete.Finished = true;
                    ProcessComplete.Success  = true;
                }
                else
                {
                    if (!clicked)
                    {
                        string js = " function doLogin() { ";
                        js += "document.getElementsByName('username')[0].value = '" + username + "'; ";
                        js += "document.getElementsByName('password')[0].value = '" + password + "'; ";
                        js += "document.getElementsByClassName('btn')[0].click(); }; ";
                        js += "setTimeout(\"doLogin()\", 1500); ";
                        InvokeScript(js);
                        clicked = true;
                        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
                        timer.Tick += (object sender, EventArgs e) =>
                        {
                            refreshed = true;
                            timer.Stop();
                            timer.Dispose();
                            //Browser.Refresh();
                            Url = "https://www.tv4play.se/";
                        };
                        timer.Interval = 3000;
                        timer.Start();
                    }
                }
            }
            else
            {
                InvokeScript("setTimeout(\"document.getElementById('player').setAttribute('style', 'position: fixed; z-index: 11000; top: 0px; left: 0px; width: 100%; height: 100%')\", 1000);");
                if (startTimer)
                {
                    startTimer = false;
                    System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
                    timer.Tick += (object sender, EventArgs e) =>
                    {
                        if (showLoading)
                        {
                            HideLoading();
                        }
                        timer.Stop();
                        timer.Dispose();
                    };

                    timer.Interval = 2250;
                    timer.Start();

                    System.Windows.Forms.Timer maxTimer = new System.Windows.Forms.Timer();
                    maxTimer.Tick += (object sender, EventArgs e) =>
                    {
                        Cursor.Position = new System.Drawing.Point(Browser.FindForm().Right - 100, Browser.FindForm().Bottom - 100);
                        Application.DoEvents();
                        Cursor.Position = new System.Drawing.Point(Browser.FindForm().Right - 35, Browser.FindForm().Bottom - 35);
                        Application.DoEvents();
                        CursorHelper.DoLeftMouseClick();
                        Application.DoEvents();
                        Cursor.Position = new System.Drawing.Point(Browser.FindForm().Right - 100, Browser.FindForm().Bottom - 100);
                        Application.DoEvents();
                        //Workaround for keeping maximized flashplayer on top
                        Browser.FindForm().Activated += FormActivated;
                        InvokeScript("document.getElementById('player').focus();"); //Prevent play/pause problem
                        maximized = true;
                        maxTimer.Stop();
                        maxTimer.Dispose();
                    };
                    maxTimer.Interval = isPremium ? 15000 : 60000;
                    maxTimer.Start();
                }
                ProcessComplete.Finished = true;
                ProcessComplete.Success  = true;
            }
            return(EventResult.Complete());
        }
示例#10
0
        /// <summary>
        /// Process a message from the web browser
        /// </summary>
        /// <returns></returns>
        public override EventResult BrowserDocumentComplete()
        {
            switch (_currentState)
            {
            case State.LoggingIn:
                if (Url.EndsWith("/signin/skygo"))
                {
                    var jsCode = "document.getElementById('username').value = '" + _username + "';";
                    jsCode += "document.getElementById('password').value = '" + _password + "';";
                    jsCode += "document.getElementById('signinform').submit();";
                    InvokeScript(jsCode);
                    _currentState = State.LoginResult;
                }
                break;

            case State.LoginResult:
                if (Url == "http://go.sky.com/")
                {
                    _currentState            = State.None;
                    ProcessComplete.Finished = true;
                    ProcessComplete.Success  = true;
                }
                else
                {
                    return(EventResult.Error("SkyGoGeneralConnector/ProcessMessage/Expected home page after log in, was actually " + Url));
                }
                break;

            case State.PlayPage:
                if (Url.Contains("/content/videos"))
                {
                    //Browser.Refresh(WebBrowserRefreshOption.Completely);// Need to do this for some reason
                    _currentState = State.None;

                    // The js code to wait for the video to appear
                    var jsCode = "setTimeout('doMaximise()', 1000);";
                    jsCode += "function doMaximise() {";
                    jsCode += "if(document.getElementsByClassName('silverlightVodPlayerWrapper') != null) {";
                    jsCode += "    document.getElementsByClassName('silverlightVodPlayerWrapper')[0].setAttribute('style', 'position: fixed; width: 100%; height: 100%; left: 0; top: 0; background: rgba(51,51,51,0.7); z-index: 10;');";
                    jsCode += "}";
                    jsCode += "else setTimeout('doMaximise()', 1000);";
                    jsCode += "}";

                    InvokeScript(jsCode);

                    var startTime = DateTime.Now;

                    _playPressThread = new Thread(new ParameterizedThreadStart(ClickPlayAfterFullScreen));
                    _playPressThread.Start();

                    ProcessComplete.Finished = true;
                    ProcessComplete.Success  = true;

                    // Wait 15 seconds for the video to start before disabling app storage - we'll do this in a separate thread
                    if (_disableAppStorageThread == null)
                    {
                        _disableAppStorageThread = new Thread(new ParameterizedThreadStart(DisableAppStorage));
                        _disableAppStorageThread.Start();
                    }

                    Browser.FindForm().Activate();
                    Browser.FindForm().Focus();
                }
                else
                {
                    if (!Url.EndsWith("/content/videos"))
                    {
                        return(EventResult.Error("SkyGoOnDemandConnector/ProcessMessage/Expected video play page, was actually " + Url));
                    }
                }
                break;

            case State.PlayPageLiveTv:
                if (Url.Contains("/detachedLiveTv.do"))
                {
                    // After 4 seconds we'll assume the page has loaded and will click in the top corner
                    var endDate = DateTime.Now.AddSeconds(4);
                    while (DateTime.Now < endDate)
                    {
                        Application.DoEvents();
                        System.Threading.Thread.Sleep(200);
                    }

                    CursorHelper.MoveMouseTo(50, 50);
                    Application.DoEvents();
                    CursorHelper.DoLeftMouseClick();
                    Application.DoEvents();
                    HideLoading();
                    Browser.FindForm().Activate();
                    Browser.FindForm().Focus();

                    ProcessComplete.Finished = true;
                    ProcessComplete.Success  = true;
                }

                break;
            }

            return(EventResult.Complete());
        }