Пример #1
0
        private void ManageExtPlayer(Process player, bool minimizeMCE, bool showSplash)
        {
            //minimize MCE if indicated
            IntPtr          mceWnd = FindWindow(null, "Windows Media Center");
            WINDOWPLACEMENT wp     = new WINDOWPLACEMENT();

            GetWindowPlacement(mceWnd, ref wp);
            if (showSplash)
            {
                //throw up a form to cover the desktop if we minimize and we are in the primary monitor
                if (System.Windows.Forms.Screen.FromHandle(mceWnd).Primary)
                {
                    ExternalSplashForm.Display(Application.CurrentInstance.ExtSplashBmp);
                }
            }
            if (minimizeMCE)
            {
                wp.showCmd = 2; // 1- Normal; 2 - Minimize; 3 - Maximize;
                SetWindowPlacement(mceWnd, ref wp);
            }
            //give the player focus
            Async.Queue("Ext Player Focus", () => GiveFocusToExtPlayer(player));
            //and wait for it to exit
            player.WaitForExit();
            //mark as watched based on if we were running long enough to play the item - take this out for now.  I think it will just be too confusing and unreliable
            //TimeSpan elapsed = DateTime.Now - startTime;
            //MediaBrowser.Library.Logging.Logger.ReportVerbose("finished playing.  played for: " + elapsed + "("+elapsed.Ticks+" ticks). Duration is " + duration + " Time required to be watched: " + TimeSpan.FromTicks((long)(duration.Ticks * (double)(Convert.ToDouble(Config.Instance.MaxResumePct) / 100))));
            //if (duration == TimeSpan.FromMinutes(0) || elapsed.Ticks >= (duration.Ticks * (double)(Convert.ToDouble(Config.Instance.MaxResumePct)/100)))
            //{
            //    MediaBrowser.Library.Logging.Logger.ReportInfo("marking watched");
            MarkWatched();
            //}
            //now re-store MCE
            wp.showCmd = 1; // 1- Normal; 2 - Minimize; 3 - Maximize;
            SetWindowPlacement(mceWnd, ref wp);
            ExternalSplashForm.Hide();
            SetForegroundWindow(mceWnd);
            Application.CurrentInstance.RunPostPlayProcesses(); //finally call the post play
        }
        private void ManageExtPlayer(Process player, PlayableItem playable)
        {
            //minimize MCE if indicated
            IntPtr          mceWnd = FindWindow(null, "Windows Media Center");
            WINDOWPLACEMENT wp     = new WINDOWPLACEMENT();

            GetWindowPlacement(mceWnd, ref wp);

            Cursor.Hide();

            if (HideTaskbar)
            {
                Taskbar.Hide();
            }

            if (ShowSplashScreen)
            {
                //throw up a form to cover the desktop if we minimize and we are in the primary monitor
                if (System.Windows.Forms.Screen.FromHandle(mceWnd).Primary)
                {
                    ExternalSplashForm.Display(Application.CurrentInstance.ExtSplashBmp);
                }
            }

            if (MinimizeMCE)
            {
                Logger.ReportVerbose("Minimizing Windows Media Center");
                wp.showCmd = 2; // 1 - Normal; 2 - Minimize; 3 - Maximize;
                SetWindowPlacement(mceWnd, ref wp);
            }

            // async this so it doesn't slow us down if the service isn't responding for some reason
            Async.Queue("Wait for external player to launch", () =>
            {
                player.Refresh();
                player.WaitForInputIdle(5000);
                OnExternalPlayerLaunched(playable);
            });

            //and wait for it to exit
            player.WaitForExit();

            player.Dispose();

            //now restore MCE
            wp.showCmd = 1; // 1 - Normal; 2 - Minimize; 3 - Maximize;
            SetWindowPlacement(mceWnd, ref wp);

            if (ShowSplashScreen)
            {
                ExternalSplashForm.Hide();
            }

            if (HideTaskbar)
            {
                Taskbar.Show();
            }

            Cursor.Show();

            SetForegroundWindow(mceWnd);

            OnPlaybackFinished(GetFinishedPlaybackState());
        }