Пример #1
0
 public static ISubEngine GetInstance(bool forceinitialize)
 {
     if (engine == null || forceinitialize)
     {
         using (Settings xmlreader = new MPSettings())
         {
             string engineType = xmlreader.GetValueAsString("subtitles", "engine", "DirectVobSub");
             if (g_Player.Player is VideoPlayerVMR9)
             {
                 if (engineType.Equals("MPC-HC"))
                 {
                     engine = new MpcEngine();
                 }
                 else if (engineType.Equals("FFDShow"))
                 {
                     engine = new FFDShowEngine();
                 }
                 else if (engineType.Equals("DirectVobSub"))
                 {
                     engine = new DirectVobSubEngine();
                 }
                 else
                 {
                     engine = new DummyEngine();
                 }
             }
             else
             {
                 engine = new DummyEngine();
             }
         }
     }
     return(engine);
 }
Пример #2
0
 public static ISubEngine GetInstance(bool forceinitialize)
 {
   if (engine == null || forceinitialize)
   {
     using (Settings xmlreader = new MPSettings())
     {
       string engineType = xmlreader.GetValueAsString("subtitles", "engine", "DirectVobSub");
       if (engineType.Equals("MPC-HC"))
         engine = new MpcEngine();
       else if (engineType.Equals("FFDShow"))
         engine = new FFDShowEngine();
       else if (engineType.Equals("DirectVobSub"))
         engine = new DirectVobSubEngine();
       else
         engine = new DummyEngine();
     }
   }
   return engine;
 }
Пример #3
0
 public Butterfly(ISubEngine sub)
 {
     _sub = sub;
 }
Пример #4
0
 public Butterfly(ISubEngine sub)
 {
     _sub = sub;
 }
Пример #5
0
        public override bool Play(string strFile)
        {
            updateTimer = DateTime.Now;
            m_speedRate = 10000;
            m_bVisible  = false;
            m_iVolume   = 100;
            m_state     = PlayState.Init;
            if (strFile != "http://localhost/OnlineVideo.mp4")
            {
                m_strCurrentFile = strFile;                                                // hack to get around the MP 1.3 Alpha bug with non http URLs
            }
            m_bFullScreen = true;
            m_ar          = GUIGraphicsContext.ARType;
            VideoRendererStatistics.VideoState = VideoRendererStatistics.State.VideoPresent;
            _updateNeeded = true;
            Log.Instance.Info("OnlineVideosPlayer: Play '{0}'", m_strCurrentFile);

            m_bStarted = false;
            if (!GetInterfaces())
            {
                m_strCurrentFile = "";
                CloseInterfaces();
                return(false);
            }

            // if we are playing a local file set the cache file so refresh rate adaption can happen
            Uri    uri      = new Uri(m_strCurrentFile);
            string protocol = uri.Scheme.Substring(0, Math.Min(uri.Scheme.Length, 4));

            if (protocol == "file")
            {
                cacheFile = m_strCurrentFile;
            }

            AdaptRefreshRateFromCacheFile();

            ISubEngine engine = SubEngine.GetInstance(true);

            if (!engine.LoadSubtitles(graphBuilder, string.IsNullOrEmpty(SubtitleFile) ? m_strCurrentFile : SubtitleFile))
            {
                SubEngine.engine = new SubEngine.DummyEngine();
            }
            else
            {
                engine.Enable = true;
            }

            IPostProcessingEngine postengine = PostProcessingEngine.GetInstance(true);

            if (!postengine.LoadPostProcessing(graphBuilder))
            {
                PostProcessingEngine.engine = new PostProcessingEngine.DummyEngine();
            }
            AnalyseStreams();
            SelectSubtitles();
            SelectAudioLanguage();
            OnInitialized();

            int hr = mediaEvt.SetNotifyWindow(GUIGraphicsContext.ActiveForm, WM_GRAPHNOTIFY, IntPtr.Zero);

            if (hr < 0)
            {
                Error.SetError("Unable to play movie", "Can not set notifications");
                m_strCurrentFile = "";
                CloseInterfaces();
                return(false);
            }
            if (videoWin != null)
            {
                videoWin.put_WindowStyle((WindowStyle)((int)WindowStyle.Child + (int)WindowStyle.ClipChildren + (int)WindowStyle.ClipSiblings));
                videoWin.put_MessageDrain(GUIGraphicsContext.form.Handle);
            }

            DirectShowUtil.SetARMode(graphBuilder, AspectRatioMode.Stretched);

            try
            {
                if (protocol == "file")
                {
                    if (Vmr9 != null)
                    {
                        Vmr9.StartMediaCtrl(mediaCtrl);
                    }
                }
                else
                {
                    hr = mediaCtrl.Run();
                    DsError.ThrowExceptionForHR(hr);
                    if (hr == 1)
                    // S_FALSE from IMediaControl::Run means: The graph is preparing to run, but some filters have not completed the transition to a running state.
                    {
                        // wait max. 20 seconds for the graph to transition to the running state
                        DateTime    startTime = DateTime.Now;
                        FilterState filterState;
                        do
                        {
                            Thread.Sleep(100);
                            hr = mediaCtrl.GetState(100, out filterState);
                            // check with timeout max. 10 times a second if the state changed
                        } while ((hr != 0) && ((DateTime.Now - startTime).TotalSeconds <= 20));
                        if (hr != 0) // S_OK
                        {
                            DsError.ThrowExceptionForHR(hr);
                            throw new Exception(string.Format("IMediaControl.GetState after 20 seconds: 0x{0} - '{1}'",
                                                              hr.ToString("X8"), DsError.GetErrorText(hr)));
                        }
                    }
                }
            }
            catch (Exception error)
            {
                Log.Instance.Warn("OnlineVideosPlayer: Unable to play with reason: {0}", error.Message);
            }
            if (hr != 0) // S_OK
            {
                Error.SetError("Unable to play movie", "Unable to start movie");
                m_strCurrentFile = "";
                CloseInterfaces();
                return(false);
            }

            if (basicVideo != null)
            {
                basicVideo.GetVideoSize(out m_iVideoWidth, out m_iVideoHeight);
            }

            if (GoFullscreen)
            {
                GUIWindowManager.ActivateWindow(GUIOnlineVideoFullscreen.WINDOW_FULLSCREEN_ONLINEVIDEO);
            }
            GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_PLAYBACK_STARTED, 0, 0, 0, 0, 0, null);

            msg.Label = CurrentFile;
            GUIWindowManager.SendThreadMessage(msg);
            m_state       = PlayState.Playing;
            m_iPositionX  = GUIGraphicsContext.VideoWindow.X;
            m_iPositionY  = GUIGraphicsContext.VideoWindow.Y;
            m_iWidth      = GUIGraphicsContext.VideoWindow.Width;
            m_iHeight     = GUIGraphicsContext.VideoWindow.Height;
            m_ar          = GUIGraphicsContext.ARType;
            _updateNeeded = true;
            SetVideoWindow();
            mediaPos.get_Duration(out m_dDuration);
            Log.Instance.Info("OnlineVideosPlayer: Duration {0} sec", m_dDuration.ToString("F"));

            return(true);
        }