Esempio n. 1
0
        public LibVlcDynamic MakeSecondMediaPlayer(Control ownerControl, string videoFileName, EventHandler onVideoLoaded, EventHandler onVideoEnded)
        {
            var newVlc = new LibVlcDynamic {
                _libVlc = _libVlc, _libVlcDll = _libVlcDll, _ownerControl = ownerControl
            };

            if (ownerControl != null)
            {
                newVlc._parentForm = ownerControl.FindForm();
            }

            newVlc.LoadLibVlcDynamic();

            newVlc.OnVideoLoaded = onVideoLoaded;
            newVlc.OnVideoEnded  = onVideoEnded;

            if (!string.IsNullOrEmpty(videoFileName))
            {
                IntPtr media = _libvlc_media_new_path(_libVlc, Encoding.UTF8.GetBytes(videoFileName + "\0"));
                newVlc._mediaPlayer = _libvlc_media_player_new_from_media(media);
                _libvlc_media_release(media);

                //  Linux: libvlc_media_player_set_xdrawable (_mediaPlayer, xdrawable);
                //  Mac: libvlc_media_player_set_nsobject (_mediaPlayer, view);
                if (ownerControl != null)
                {
                    _libvlc_media_player_set_hwnd(newVlc._mediaPlayer, ownerControl.Handle); // windows
                }
                if (onVideoEnded != null)
                {
                    newVlc._videoEndTimer = new Timer {
                        Interval = 500
                    };
                    newVlc._videoEndTimer.Tick += VideoEndTimerTick;
                    newVlc._videoEndTimer.Start();
                }

                _libvlc_media_player_play(newVlc._mediaPlayer);
                newVlc._videoLoadedTimer = new Timer {
                    Interval = 100
                };
                newVlc._videoLoadedTimer.Tick += newVlc.VideoLoadedTimer_Tick;
                newVlc._videoLoadedTimer.Start();

                newVlc._mouseTimer = new Timer {
                    Interval = 25
                };
                newVlc._mouseTimer.Tick += newVlc.MouseTimerTick;
                newVlc._mouseTimer.Start();
            }
            return(newVlc);
        }
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 protected override void Dispose(bool disposing)
 {
     if (disposing && (components != null))
     {
         components.Dispose();
         if (_libVlc != null)
         {
             _libVlc.Dispose();
             _libVlc = null;
         }
     }
     base.Dispose(disposing);
 }
Esempio n. 3
0
 private void HardSubExtract_Shown(object sender, EventArgs e)
 {
     if (openFileDialogVideo.ShowDialog(this) == DialogResult.OK)
     {
         _videoFileName = openFileDialogVideo.FileName;
         tbFileName.Text = openFileDialogVideo.FileName;
         _videoInfo = UiUtil.GetVideoInfo(_videoFileName);
         var oldPlayer = Configuration.Settings.General.VideoPlayer;
         Configuration.Settings.General.VideoPlayer = "VLC";
         UiUtil.InitializeVideoPlayerAndContainer(_videoFileName, _videoInfo, mediaPlayer, VideoLoaded, null);
         Configuration.Settings.General.VideoPlayer = oldPlayer;
         _libVlc = mediaPlayer.VideoPlayer as LibVlcDynamic;
     }
     else
     {
         DialogResult = DialogResult.Cancel;
     }
 }
Esempio n. 4
0
        public LibVlcDynamic MakeSecondMediaPlayer(Control ownerControl, string videoFileName, EventHandler onVideoLoaded, EventHandler onVideoEnded)
        {
            var newVlc = new LibVlcDynamic { _libVlc = _libVlc, _libVlcDLL = _libVlcDLL, _ownerControl = ownerControl };
            if (ownerControl != null)
                newVlc._parentForm = ownerControl.FindForm();

            newVlc.LoadLibVlcDynamic();

            newVlc.OnVideoLoaded = onVideoLoaded;
            newVlc.OnVideoEnded = onVideoEnded;

            if (!string.IsNullOrEmpty(videoFileName))
            {
                IntPtr media = _libvlc_media_new_path(_libVlc, Encoding.UTF8.GetBytes(videoFileName + "\0"));
                newVlc._mediaPlayer = _libvlc_media_player_new_from_media(media);
                _libvlc_media_release(media);

                //  Linux: libvlc_media_player_set_xdrawable (_mediaPlayer, xdrawable);
                //  Mac: libvlc_media_player_set_nsobject (_mediaPlayer, view);
                _libvlc_media_player_set_hwnd(newVlc._mediaPlayer, ownerControl.Handle); // windows

                if (onVideoEnded != null)
                {
                    newVlc._videoEndTimer = new Timer { Interval = 500 };
                    newVlc._videoEndTimer.Tick += VideoEndTimerTick;
                    newVlc._videoEndTimer.Start();
                }

                _libvlc_media_player_play(newVlc._mediaPlayer);
                newVlc._videoLoadedTimer = new Timer { Interval = 100 };
                newVlc._videoLoadedTimer.Tick += newVlc.VideoLoadedTimer_Tick;
                newVlc._videoLoadedTimer.Start();

                newVlc._mouseTimer = new Timer { Interval = 25 };
                newVlc._mouseTimer.Tick += newVlc.MouseTimerTick;
                newVlc._mouseTimer.Start();
            }
            return newVlc;
        }
        /// <summary>
        /// The fill preview background.
        /// </summary>
        /// <param name="bmp">
        /// The bmp.
        /// </param>
        /// <param name="g">
        /// The g.
        /// </param>
        /// <param name="p">
        /// The p.
        /// </param>
        private void FillPreviewBackground(Bitmap bmp, Graphics g, Paragraph p)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(this._videoFileName) && LibVlcDynamic.IsInstalled)
                {
                    using (var vlc = new LibVlcDynamic())
                    {
                        vlc.Initialize(this.panelVlcTemp, this._videoFileName, null, null);
                        Application.DoEvents();
                        vlc.Volume = 0;
                        vlc.Pause();
                        vlc.CurrentPosition = p.StartTime.TotalSeconds;
                        Application.DoEvents();
                        var fileName = Path.GetTempFileName() + ".bmp";
                        vlc.TakeSnapshot(fileName, (uint)bmp.Width, (uint)bmp.Height);
                        Application.DoEvents();
                        Thread.Sleep(200);
                        using (var tempBmp = new Bitmap(fileName))
                        {
                            g.DrawImageUnscaled(tempBmp, new Point(0, 0));
                        }
                    }

                    return;
                }
            }
            catch
            {
                // Was unable to grap screenshot via vlc
            }

            // Draw background with generated image
            var rect = new Rectangle(0, 0, bmp.Width - 1, bmp.Height - 1);
            using (var br = new LinearGradientBrush(rect, Color.Black, Color.Black, 0, false))
            {
                var cb = new ColorBlend { Positions = new[] { 0, 1 / 6f, 2 / 6f, 3 / 6f, 4 / 6f, 5 / 6f, 1 }, Colors = new[] { Color.Black, Color.Black, Color.White, Color.Black, Color.Black, Color.White, Color.Black } };
                br.InterpolationColors = cb;
                br.RotateTransform(0);
                g.FillRectangle(br, rect);
            }
        }
        public LibVlcDynamic MakeSecondMediaPlayer(Control ownerControl, string videoFileName, EventHandler onVideoLoaded, EventHandler onVideoEnded)
        {
            var newVlc = new LibVlcDynamic { libVlc = libVlc, libVlcDll = libVlcDll, ownerControl = ownerControl };
            if (ownerControl != null)
            {
                newVlc.parentForm = ownerControl.FindForm();
            }

            newVlc.LoadLibVlcDynamic();

            newVlc.OnVideoLoaded = onVideoLoaded;
            newVlc.OnVideoEnded = onVideoEnded;

            if (string.IsNullOrEmpty(videoFileName))
            {
                return newVlc;
            }

            IntPtr media = libvlcMediaNewPath(libVlc, Encoding.UTF8.GetBytes(videoFileName + "\0"));
            newVlc.mediaPlayer = libvlcMediaPlayerNewFromMedia(media);
            libvlcMediaRelease(media);

            //  Linux: libvlc_media_player_set_xdrawable (_mediaPlayer, xdrawable);
            //  Mac: libvlc_media_player_set_nsobject (_mediaPlayer, view);
            if (ownerControl != null)
            {
                libvlcMediaPlayerSetHwnd(newVlc.mediaPlayer, ownerControl.Handle); // windows
            }

            if (onVideoEnded != null)
            {
                newVlc.videoEndTimer = new Timer { Interval = 500 };
                newVlc.videoEndTimer.Tick += VideoEndTimerTick;
                newVlc.videoEndTimer.Start();
            }

            libvlcMediaPlayerPlay(newVlc.mediaPlayer);
            newVlc.videoLoadedTimer = new Timer { Interval = 100 };
            newVlc.videoLoadedTimer.Tick += newVlc.VideoLoadedTimer_Tick;
            newVlc.videoLoadedTimer.Start();

            newVlc.mouseTimer = new Timer { Interval = 25 };
            newVlc.mouseTimer.Tick += newVlc.MouseTimerTick;
            newVlc.mouseTimer.Start();
            return newVlc;
        }
 /// <summary>
 /// The hard sub extract_ shown.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 private void HardSubExtract_Shown(object sender, EventArgs e)
 {
     if (this.openFileDialogVideo.ShowDialog(this) == DialogResult.OK)
     {
         this._videoFileName = this.openFileDialogVideo.FileName;
         this.tbFileName.Text = this.openFileDialogVideo.FileName;
         this._videoInfo = Utilities.GetVideoInfo(this._videoFileName);
         var oldPlayer = Configuration.Settings.General.VideoPlayer;
         Configuration.Settings.General.VideoPlayer = "VLC";
         Utilities.InitializeVideoPlayerAndContainer(this._videoFileName, this._videoInfo, this.mediaPlayer, this.VideoLoaded, null);
         Configuration.Settings.General.VideoPlayer = oldPlayer;
         this._libVlc = this.mediaPlayer.VideoPlayer as LibVlcDynamic;
     }
     else
     {
         this.DialogResult = DialogResult.Cancel;
     }
 }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">
        /// true if managed resources should be disposed; otherwise, false.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
                if (this._libVlc != null)
                {
                    this._libVlc.Dispose();
                    this._libVlc = null;
                }
            }

            base.Dispose(disposing);
        }