public override void Unload()
 {
     log.InfoFormat("BrowserCodec[{0}]: unload", ID());
     Stop();
     if (Root.Instance != null)
     {
         Root.Instance.FrameStarted -= new FrameEvent(FrameStarted);
     }
     if (browser != null)
     {
         if (browser.IsHandleCreated)
         {
             browser.Close();
         }
         browser = null;
     }
     base.Unload();
     return;
 }
        void FrameStarted(object source, FrameEventArgs e)
        {
            try {
                if (texture == null ||
                    !(texture is D3DTexture) ||
                    ((texture as D3DTexture).DXTexture) == null ||
                    ((texture as D3DTexture).DXTexture as D3D.Texture) == null)
                    return;
                D3D.Surface d3dsurface = ((texture as D3DTexture).DXTexture as D3D.Texture).GetSurfaceLevel(0);
                if (ps == PLAY_STATE.BUFFERING)
                {
                    if (browser == null)
                    {
                        browser = new Browser();
                        browser.SetObjectForScripting(scriptingObj);
                        browser.SetSize(VideoSize());
                        CreateTexture();
                        bool ans = browser.Open(path);
                        if (ans == false)
                        {
                            ps = PLAY_STATE.STOPPED;
                            browser = null;
                        }
                    }

                    if (browser.Loaded())
                    {
                        Play();
                    }
                    else
                    {
                        Graphics g = d3dsurface.GetGraphics();
                        string text;
                        int pct = browser.LoadPercent();
                        if ((pct == 100) || (pct == 0))
                        {
                            text = string.Format("Loading ({0}%)", pct);
                        }
                        else
                        {
                            text = string.Format("Loading ({0:d2}%)", pct);
                        }
                        switch ((count++ / 10) % 3)
                        {
                            case 0:
                                text += ".";
                                break;
                            case 1:
                                text += "..";
                                break;
                            case 2:
                                text += "...";
                                break;
                        }
                        g.Clear(Color.Black);
                        g.DrawString(text, loadingFont, Brushes.White, loadingPoint);
                        d3dsurface.ReleaseGraphics();
                    }
                }
                if(ps == PLAY_STATE.RUNNING)
                {
                    Graphics g = d3dsurface.GetGraphics();
                    browser.RenderTo(g);
                    d3dsurface.ReleaseGraphics();
                }
            }
            catch (Exception exc) {
                log.WarnFormat("BrowserMovie.FrameStarted exception: {0}, stack trace {1}",
                    exc.Message, exc.StackTrace);
            }
        }
 public BrowserMovie()
     : base()
 {
     browser = null;
     scriptingObj = defaultScriptingObj;
 }