示例#1
0
        //-------------------------------------------------------------------------
        // 停止
        //-------------------------------------------------------------------------
        public static void Stop()
        {
            if (Properties.Settings.Default.fme_gui)
            {
                FMEGUI.Kill();
            }
            else
            {
                Process[] ps = Process.GetProcessesByName("FMLECmd");

                foreach (System.Diagnostics.Process p in ps)
                {
                    try
                    {
                        p.Kill();
                    }
                    catch (Exception e) {
                        Utils.WriteLog("FMLE() " + e.Message);
                    }
                }

                ps = Process.GetProcessesByName("FlashMediaLiveEncoder");

                foreach (System.Diagnostics.Process p in ps)
                {
                    p.Kill();
                }

                // すべてのFMEがいなくなったことを確認する
                do
                {
                    System.Threading.Thread.Sleep(500);
                    ps = Process.GetProcessesByName("FlashMediaLiveEncoder");
                } while (ps.Length > 0);
            }
            mFMEStarted = false;
            DeleteSessionfile();
        }
示例#2
0
        //-------------------------------------------
        // PushStart
        //-------------------------------------------
        public static bool PushStart()
        {
            const int padding  = 10;
            const int padding2 = 10;

            mFMEStarted = false;

            // プロセスが確保されていなければ、リターン
            if (mFMEprocess == null)
            {
                return(false);
            }

            // プロセスが存在しても、終了していれば、リターン
            if (mFMEprocess.HasExited)
            {
                return(false);
            }

            // ウインドウのサイズをあわせる
            FitWindowSize();

            RECT clientrect = new RECT();


            // クライアント領域のスクリーンをキャプチャする
            Bitmap bmp = null;


            bool bStartPushed   = false;
            bool bStartComplete = false;

            using (ScreenCapture scr = new ScreenCapture())
            {
                int   i;
                Point outPos = new Point();

                Point start_offs = new Point(417, 512);
                Point stop_offs  = new Point(556, 512);
                Point ng_offs    = new Point(489, 357);


                // スタートボタンを探して押す
                for (i = 0; i < 60; i++)
                {
                    // ウインドウをフォアグラウンドに
                    SetForegroundWindow(m_fme_hwnd);  // アクティブにする

                    // クライアント領域のサイズを取得
                    GetClientRect(m_fme_hwnd, ref clientrect);
                    POINT p1, p2;
                    p1.x = clientrect.left;
                    p1.y = clientrect.top;
                    p2.x = clientrect.right;
                    p2.y = clientrect.bottom;

                    //クライアント領域座標をスクリーン座標に変換
                    ClientToScreen(m_fme_hwnd, ref p1);
                    ClientToScreen(m_fme_hwnd, ref p2);

                    // クライアント領域のレクトアングルを設定
                    Rectangle iRect = new Rectangle(p1.x, p1.y, p2.x - p1.x + 1, p2.y - p1.y + 1);

                    bmp = scr.Capture(iRect);
                    if (ContainBitmap(mStartBmp, bmp, start_offs.X - padding2, start_offs.Y - padding, start_offs.X + padding2, start_offs.Y + padding, ref outPos, 5))
                    {
                        MouseClick(p1.x + outPos.X + 18, p1.y + outPos.Y + 14);
                        bStartPushed = true;
                        // 立ち上がるのを待つ
                        using (Bouyomi bm = new Bouyomi())
                        {
                            bm.Talk("スタートボタン、プッシュ");
                        }
                        break;
                    }

                    bmp.Dispose();
                    bmp = null;
                    FitWindowSize();
                    // 0.5[s] wait
                    System.Threading.Thread.Sleep(500);
                }

                // スタートボタンが押せなかった場合
                if (!bStartPushed)
                {
                    if (bmp != null)
                    {
                        bmp.Dispose();
                        bmp = null;
                    }
                    // 立ち上がるのを待つ
                    using (Bouyomi bm = new Bouyomi())
                    {
                        bm.Talk("スタートボタンを代わりに押してください");
                    }
                }

                // スタートできたかのチェック
                for (i = 0; i < 40; i++)
                {
                    // ウインドウをフォアグラウンドに
                    SetForegroundWindow(m_fme_hwnd);  // アクティブにする

                    GetClientRect(m_fme_hwnd, ref clientrect);
                    POINT p1, p2;
                    p1.x = clientrect.left;
                    p1.y = clientrect.top;
                    p2.x = clientrect.right;
                    p2.y = clientrect.bottom;

                    //クライアント領域座標をスクリーン座標に変換
                    ClientToScreen(m_fme_hwnd, ref p1);
                    ClientToScreen(m_fme_hwnd, ref p2);

                    Rectangle iRect = new Rectangle(p1.x, p1.y, p2.x - p1.x + 1, p2.y - p1.y + 1);

                    bmp = scr.Capture(iRect);

                    // Stop が押せるようになれば、とりあえず成功判定
                    if (ContainBitmap(mStopBmp, bmp, stop_offs.X - padding2, stop_offs.Y - padding, stop_offs.X + padding2, stop_offs.Y + padding, ref outPos, 5))
                    {
                        // 立ち上がるのを待つ
                        using (Bouyomi bm = new Bouyomi())
                        {
                            bm.Talk("ストップボタン、点灯確認");
                        }
                        bStartComplete = true;
                        mFMEStarted    = true;
                        bmp.Dispose();
                        bmp = null;
                        break;
                    }

                    // NGダイアログが出てきたら、NG判定
                    if (ContainBitmap(mNgBmp, bmp, ng_offs.X - padding2, ng_offs.Y - padding, ng_offs.X + padding2, ng_offs.Y + padding, ref outPos, 5))
                    {
                        MouseClick(p1.x + outPos.X + 10, p1.y + outPos.Y + 10);
                        if (bmp != null)
                        {
                            bmp.Dispose();
                            bmp = null;
                        }

                        // NG ダイアログが消えるのを待つ
                        int j;
                        for (j = 0; j < 10; j++)
                        {
                            GetClientRect(m_fme_hwnd, ref clientrect);

                            p1.x = clientrect.left;
                            p1.y = clientrect.top;
                            p2.x = clientrect.right;
                            p2.y = clientrect.bottom;

                            //クライアント領域座標をスクリーン座標に変換
                            ClientToScreen(m_fme_hwnd, ref p1);
                            ClientToScreen(m_fme_hwnd, ref p2);

                            iRect = new Rectangle(p1.x, p1.y, p2.x - p1.x + 1, p2.y - p1.y + 1);

                            bmp = scr.Capture(iRect);
                            if (!ContainBitmap(mNgBmp, bmp, ng_offs.X - padding2, ng_offs.Y - padding, ng_offs.X + padding2, ng_offs.Y + padding, ref outPos, 5))
                            {
                                if (bmp != null)
                                {
                                    bmp.Dispose();
                                    bmp = null;
                                }
                                break;
                            }
                            // 0.5[s] wait
                            System.Threading.Thread.Sleep(500);
                        }
                        break;
                    }
                    if (bmp != null)
                    {
                        bmp.Dispose();
                        bmp = null;
                    }

                    // 0.5[s] wait
                    FitWindowSize();
                    System.Threading.Thread.Sleep(500);
                }
            }

            //// Start領域
            //iRect = new Rectangle(p1.x+417, p1.y+512, 36, 28);
            //bmp = scr.Capture(iRect);
            //filePath = @"F:\FMEstart.bmp";
            //bmp.Save(filePath, ImageFormat.Bmp);

            //// Stop領域
            //iRect = new Rectangle(p1.x + 556, p1.y + 512, 34, 28);
            //bmp = scr.Capture(iRect);
            //filePath = @"F:\FMEstop.bmp";
            //bmp.Save(filePath, ImageFormat.Bmp);

            //// NG領域
            //iRect = new Rectangle(p1.x + 489, p1.y + 357, 21, 19);
            //bmp = scr.Capture(iRect);
            //filePath = @"F:\FMEng.bmp";
            //bmp.Save(filePath, ImageFormat.Bmp);

            //filePath = @"F:\screen.bmp";
            //Process.Start(filePath);

            //一秒間(1000ミリ秒)停止する
            System.Threading.Thread.Sleep(2000);

            if (bStartComplete)
            {
                using (Bouyomi bm = new Bouyomi())
                {
                    bm.Talk("えふえむいー配信を開始しました");
                }
            }
            else
            {
                using (Bouyomi bm = new Bouyomi())
                {
                    bm.Talk("えふえむいー起動失敗しました");
                }
                FMEGUI.Kill();
            }

            // ウインドウを最小化する
            ShowWindow(m_fme_hwnd, SW_MINIMIZE);
            return(bStartComplete);
        }