コード例 #1
0
        /// <summary>
        /// ForegroundWindow management and MediaPlayer setup.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (!IsDesignMode)
            {
                var windowsFormsHost = Template.FindName(PART_PlayerHost, this) as FrameworkElement;
                if (windowsFormsHost != null)
                {
                    ForegroundWindow = new ForegroundWindow(windowsFormsHost)
                    {
                        Content = ViewContent
                    };
                }

                Hwnd = (Template.FindName(PART_PlayerView, this) as System.Windows.Forms.Panel)?.Handle ?? IntPtr.Zero;
                if (Hwnd == null)
                {
                    Trace.WriteLine("HWND is NULL, aborting...");
                    return;
                }

                if (MediaPlayer == null)
                {
                    Trace.Write("No MediaPlayer is set, aborting...");
                    return;
                }

                MediaPlayer.Hwnd = Hwnd;
            }
        }
コード例 #2
0
        /// <summary>
        /// Unhook mediaplayer and dispose foreground window
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (MediaPlayer != null)
                    {
                        MediaPlayer.Hwnd = IntPtr.Zero;
                    }

                    WindowsFormsHost?.Dispose();
                    ForegroundWindow?.Close();
                }

                ViewContent      = null;
                ForegroundWindow = null;
                disposedValue    = true;
            }
        }
コード例 #3
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (!IsDesignMode)
            {
                var windowsFormsHost = Template.FindName(PART_PlayerHost, this) as FrameworkElement;
                if (windowsFormsHost != null)
                {
                    ForegroundWindow         = new ForegroundWindow(windowsFormsHost);
                    ForegroundWindow.Content = ViewContent;
                }

                var hwnd = (Template.FindName(PART_PlayerView, this) as System.Windows.Forms.Panel)?.Handle;
                if (hwnd != null)
                {
                    MediaPlayer.Hwnd = (IntPtr)hwnd;
                }
            }
        }
コード例 #4
0
ファイル: VideoView.cs プロジェクト: rookiejava/libvlcsharp
        public VideoView()
        {
            var res = Application.LoadComponent(new Uri("/LibVLCSharp.WPF;component/Styles/VideoView.xaml", UriKind.RelativeOrAbsolute)) as ResourceDictionary;

            Style = res["VideoViewStyle"] as Style;

            _foreground = new ForegroundWindow(this);

            Core.Initialize();

            LibVLC      = new LibVLC();
            MediaPlayer = new MediaPlayer(LibVLC);

            SizeChanged += OnSizeChanged;

            _controlHeight = Height;
            _controlWidth  = Width;

            Loaded   += VideoView_Loaded;
            Unloaded += VideoView_Unloaded;
        }