Пример #1
0
        private void InitializeMediaEngine()
        {
            MediaEngine = MediaEngineServiceProvider.GetMediaEngine(this);
            MediaEngine.MediaWindowDisposed += delegate(object sender, EventArgs args)
            {
                if (_mediaWindow != null)
                {
                    _mediaWindow.MessageReceived -= new EventHandler <MessageReceivedEventArgs>(_mediaWindow_MessageReceived);
                    _mediaWindow = null;
                }

                SetMediaWindowState(false);
            };

            MediaEngine.InitSize += (sender, args) =>
            {
                _rcSrc             = args.NewVideSize;
                _nativeAspectRatio = args.NativeAspectRatio;

                if (args.Initial)
                {
                    var matrix       = this.GetTargetMatrix();
                    var newVideoSize = (Size)matrix.Transform((Vector) new Size(args.NewVideSize.cx, args.NewVideSize.cy));

                    OnInitSize(newVideoSize);
                }

                ResizeNormal(args.Initial);

                if (args.InvalidateSuggested)
                {
                    InvalidateMediaWindow();
                }
            };
        }
Пример #2
0
        private void CleanUpMediaWindow()
        {
            _mediaWindow.MessageReceived -= new EventHandler <MessageReceivedEventArgs>(_mediaWindow_MessageReceived);
            _mediaWindow.Dispose();
            _mediaWindow = null;

            OnMediaWindowDisposed(EventArgs.Empty);
        }
        protected override HandleRef BuildWindowCore(HandleRef hwndParent)
        {
            var hostHandle = WindowsManagement.CreateWindowEx(0,
                                                              "static",
                                                              "",
                                                              WindowsManagement.WS_VISIBLE | WindowsManagement.WS_CHILD | WindowsManagement.WS_CLIPSIBLINGS,
                                                              0,
                                                              0,
                                                              0,
                                                              0,
                                                              hwndParent.Handle,
                                                              IntPtr.Zero,
                                                              IntPtr.Zero,
                                                              IntPtr.Zero);

            _mediaWindow = new MediaWindow(hostHandle, 0, 0);

            return(new HandleRef(this, hostHandle));
        }
Пример #4
0
        private void CreateMediaWindow()
        {
            var window = Application.Current.MainWindow;
            var helper = new WindowInteropHelper(window);

            var matrix         = window.GetDeviceMatrix();
            var windowLocation = matrix.Transform(new Point(window.Left, window.Top));

            var transformToWindow = TransformToAncestor(window);
            var relativeLocation  = transformToWindow.Transform(new Point(0, 0));

            var screenLocation = new Point(windowLocation.X + relativeLocation.X, windowLocation.Y + relativeLocation.Y);

            //   var screenSize = (Size)matrix.Transform((Vector)new Size(ActualWidth, ActualHeight));

            _mediaWindow = new MediaWindow(helper.Handle, (int)Math.Ceiling(screenLocation.X), (int)Math.Ceiling(screenLocation.Y),
                                           /*(int)Math.Floor(screenSize.Width)*/ 0, /*(int)Math.Floor(screenSize.Height)*/ 0,
                                           WindowsManagement.WS_VISIBLE | WindowsManagement.WS_POPUP);
            _mediaWindow.MessageReceived += new EventHandler <MessageReceivedEventArgs>(_mediaWindow_MessageReceived);
        }
Пример #5
0
        /// <summary>
        /// Render new media.
        /// </summary>
        /// <param name="source">Filename.</param>
        /// <param name="mediaSourceType">One of the MediaSourceType.</param>
        /// <returns></returns>
        public bool BuildGraph(string source, MediaSourceType mediaSourceType)
        {
            ResetGraph();

            _mediaWindow = _mediaWindowHost.GetMediaWindow();
            _mediaWindow.MessageReceived += _mediaWindow_MessageReceived;

            _filterGraph = FilterGraphBuilder.BuildFilterGraph(source,
                                                               mediaSourceType,
                                                               _mediaWindow.Handle,
                                                               _preferredRenderer,
                                                               ReportError,
                                                               delegate(string message)
            {
                UserDecisionEventArgs args = new UserDecisionEventArgs(message);
                OnPartialSuccess(args);
                return(args.Accept);
            });
            if (_filterGraph != null)
            {
                _mediaWindow.SetRendererInterfaces(
                    _filterGraph.Renderer is IVMRWindowless ? ((IVMRWindowless)_filterGraph.Renderer).VMRWindowlessControl : null,
                    _filterGraph.Renderer is IVMR9Windowless ? ((IVMR9Windowless)_filterGraph.Renderer).VMRWindowlessControl : null,
                    _filterGraph.Renderer is IEVR ? ((IEVR)_filterGraph.Renderer).MFVideoDisplayControl : null);

                _filterGraph.GraphError       += (sender, args) => ReportError(args);
                _filterGraph.PlayBackComplete += (sender, arges) =>
                {
                    if (_repeat)
                    {
                        if (_filterGraph.IsGraphSeekable)
                        {
                            SetCurrentPosition(0);
                        }
                        else // gonna have to think it over!
                        {
                            SetCurrentPosition(0);
                        }
                    }
                    else
                    {
                        StopGraph();
                    }
                };
                _filterGraph.ErrorAbort += (sender, args) =>
                {
                    ResetGraph();
                    ReportError(String.Format("{0} {1}", Resources.Resources.mw_error_occured,
                                              Resources.Resources.mw_play_aborted));
                };
                _filterGraph.FailedStreamsAvailable += OnFailedStreamsAvailableInternal;

                var dvdFilterGraph = _filterGraph as IDvdFilterGraph;
                if (dvdFilterGraph != null)
                {
                    dvdFilterGraph.ModifyMenu        += (sender, args) => OnModifyMenu();
                    dvdFilterGraph.DiscEjected       += (sender, args) => ResetGraph();
                    dvdFilterGraph.InitSize          += (sender, args) => OnInitSize(false, true);
                    dvdFilterGraph.DvdParentalChange += (sender, args) => args.Raise(this, ref DvdParentalChange);
                }

                OnInitSize(true, true);
                IsMuted = IsMuted; // this resets the volume

                return(!_autoPlay || ResumeGraph());
            }
            else
            {
                CleanUpMediaWindow();
                return(false);
            }
        }
Пример #6
0
            public void HandleMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
            {
                switch (msg)
                {
                case (uint)WindowsMessages.WM_LBUTTONDBLCLK:
                    _doubleClick = true;
                    _mwh.RaiseEvent(new RoutedEventArgs(MWDoubleClickEvent));
                    break;

                case (uint)WindowsMessages.WM_CONTEXTMENU:
                {
                    var args = CreateScreenPositionEventArgs();
                    args.RoutedEvent = MWContextMenuEvent;
                    _mwh.RaiseEvent(args);
                }
                break;

                case (uint)WindowsMessages.WM_LBUTTONUP:
                {
                    IMediaWindow mediaWindow = _host.GetMediaWindow();
                    if (mediaWindow != null && mediaWindow.Handle == hWnd && _mwh.MediaEngine.IsMenuOn)
                    {
                        uint mylParam = (uint)lParam;
                        uint x        = mylParam & 0x0000FFFF;
                        uint y        = mylParam & 0xFFFF0000;
                        y >>= 16;

                        GDI.POINT pt = new GDI.POINT();
                        pt.x = (int)x;
                        pt.y = (int)y;
                        _mwh.MediaEngine.ActivateDvdMenuButtonAtPosition(pt);
                    }

                    if (!_mwh.MediaEngine.IsMenuOn && !_doubleClick)
                    {
                        _mwh.RaiseEvent(new RoutedEventArgs(MWClickEvent));
                    }
                    _doubleClick = false;
                }
                break;

                case (uint)WindowsMessages.WM_MOUSEMOVE:
                    if ((uint)lParam != _previousMousePosition)     // mouse was actually moved as its position has changed
                    {
                        _previousMousePosition = (uint)lParam;

                        IMediaWindow mediaWindow = _host.GetMediaWindow();
                        if (mediaWindow != null && mediaWindow.Handle == hWnd && _mwh.MediaEngine.IsMenuOn)
                        {
                            uint mylParam = (uint)lParam;
                            uint x        = mylParam & 0x0000FFFF;
                            uint y        = mylParam & 0xFFFF0000;
                            y >>= 16;

                            GDI.POINT pt = new GDI.POINT();
                            pt.x = (int)x;
                            pt.y = (int)y;
                            _mwh.MediaEngine.SelectDvdMenuButtonAtPosition(pt);
                        }

                        if (!_mouseOnWindow)
                        {
                            WindowsManagement.TRACKMOUSEEVENT tme =
                                new WindowsManagement.TRACKMOUSEEVENT();
                            tme.cbSize      = Marshal.SizeOf(tme);
                            tme.dwFlags     = WindowsManagement.TME_LEAVE;
                            tme.dwHoverTime = WindowsManagement.HOVER_DEFAULT;
                            tme.hwndTrack   = hWnd;

                            WindowsManagement._TrackMouseEvent(ref tme);
                            _mouseOnWindow = true;
                            _mwh.RaiseEvent(new RoutedEventArgs(MWMouseEnterEvent));
                        }

                        var args = CreateScreenPositionEventArgs();
                        args.RoutedEvent = MWMouseMoveEvent;
                        _mwh.RaiseEvent(args);
                    }
                    break;

                case (uint)WindowsMessages.WM_MOUSELEAVE:
                    _mouseOnWindow = false;
                    _mwh.RaiseEvent(new RoutedEventArgs(MWMouseLeaveEvent));
                    break;

                case (uint)WindowsMessages.WM_KEYDOWN:
                    var modifiers = Keyboard.Modifiers;
                    var code      = wParam.ToInt32();
                    var key       = KeyInterop.KeyFromVirtualKey(code);

                    var handled = HandleKey(key);

                    if (!handled)
                    {
                        _mwh.RaiseEvent(new MWKeyEventArgs(MWKeyDownEvent, key, modifiers));
                    }
                    break;

                case (uint)WindowsMessages.WM_MOUSEWHEEL:
                    uint delta = ((uint)wParam) & 0xFFFF0000;
                    delta >>= 16;
                    _mwh.RaiseEvent(new MWMouseWheelEventArgs(MWMouseWheelEvent, (short)delta));     // it's WORD (2 bytes)
                    break;
                }
            }
Пример #7
0
            public void HandleMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam)
            {
                switch (Msg)
                {
                case (uint)WindowsMessages.WM_LBUTTONDBLCLK:
                    _doubleClick = true;
                    if (_mwh.MWDoubleClick != null)
                    {
                        _mwh.MWDoubleClick(_mwh, EventArgs.Empty);
                    }
                    break;

                case (uint)WindowsMessages.WM_CONTEXTMENU:
                    if (!_trackingContextMenu)
                    {
                        _trackingContextMenu = true;
                        if (_mwh.MWContextMenu != null)
                        {
                            _mwh.MWContextMenu(Cursor.Position);
                        }
                    }
                    else
                    {
                        _trackingContextMenu = false;
                    }
                    break;

                case (uint)WindowsMessages.WM_LBUTTONUP:
                {
                    IMediaWindow mediaWindow = _host.GetMediaWindow();
                    if (mediaWindow != null && mediaWindow.Handle == hWnd && _mwh._engine.IsMenuOn)
                    {
                        uint mylParam = (uint)lParam;
                        uint x        = mylParam & 0x0000FFFF;
                        uint y        = mylParam & 0xFFFF0000;
                        y >>= 16;

                        GDI.POINT pt = new GDI.POINT();
                        pt.x = (int)x;
                        pt.y = (int)y;
                        _mwh._engine.ActivateDvdMenuButtonAtPosition(pt);
                    }

                    if (!_mwh._engine.IsMenuOn && !_doubleClick && _mwh.MWClick != null)
                    {
                        _mwh.MWClick(_mwh, EventArgs.Empty);
                    }
                    _doubleClick = false;
                }
                break;

                case (uint)WindowsMessages.WM_MOUSEMOVE:
                    if ((uint)lParam != _previousMousePosition)     // mouse was actually moved as its position has changed
                    {
                        _previousMousePosition = (uint)lParam;

                        IMediaWindow mediaWindow = _host.GetMediaWindow();
                        if (mediaWindow != null && mediaWindow.Handle == hWnd && _mwh._engine.IsMenuOn)
                        {
                            uint mylParam = (uint)lParam;
                            uint x        = mylParam & 0x0000FFFF;
                            uint y        = mylParam & 0xFFFF0000;
                            y >>= 16;

                            GDI.POINT pt = new GDI.POINT();
                            pt.x = (int)x;
                            pt.y = (int)y;
                            _mwh._engine.SelectDvdMenuButtonAtPosition(pt);
                        }

                        if (!_mwh._mouseOnWindow)
                        {
                            WindowsManagement.TRACKMOUSEEVENT tme =
                                new WindowsManagement.TRACKMOUSEEVENT();
                            tme.cbSize      = Marshal.SizeOf(tme);
                            tme.dwFlags     = WindowsManagement.TME_LEAVE;
                            tme.dwHoverTime = WindowsManagement.HOVER_DEFAULT;
                            tme.hwndTrack   = hWnd;

                            WindowsManagement._TrackMouseEvent(ref tme);
                            _mwh._mouseOnWindow = true;
                            if (_mwh.MWMouseEnter != null)
                            {
                                _mwh.MWMouseEnter(_mwh, EventArgs.Empty);
                            }
                        }

                        if (_mwh.MWMouseMove != null)
                        {
                            _mwh.MWMouseMove(_mwh, EventArgs.Empty);
                        }
                    }
                    break;

                case (uint)WindowsMessages.WM_MOUSELEAVE:
                    _mwh._mouseOnWindow = false;
                    if (_mwh.MWMouseLeave != null)
                    {
                        _mwh.MWMouseLeave(_mwh, EventArgs.Empty);
                    }
                    break;
                }
            }