Пример #1
0
        private void DisposePlayer()
        {
            if (_mFactory == null)
            {
                return;
            }
            try
            {
                _mPlayer.Dispose();
            }
            catch { }
            try
            {
                _mFactory.Dispose();
            }
            catch { }
            try
            {
                _mMedia.Dispose();
            }
            catch { }

            _mPlayer  = null;
            _mFactory = null;
            _mMedia   = null;
        }
Пример #2
0
        public virtual void Open(IMediaPlayerFactory factory, string s)
        {
            if (m_currentMedia != null)
            {
                m_currentMedia.Dispose();
            }

            m_currentMedia = factory.CreateMedia <IMedia>(s);

            LibVlcMethods.libvlc_media_player_set_media(m_hMediaPlayer, ((INativePointer)m_currentMedia).Pointer);
            //LibVlcMethods.libvlc_media_release(((INativePointer)m_currentMedia).Pointer);
        }
Пример #3
0
        public bool Start(string videoSrcUrl)
        {
            if (_bIsInitial)
            {
                return(true);
            }

            _bIsInitial = true;
            try
            {
                if (_vlcmedia != null)
                {
                    _vlcmedia.Events.StateChanged    -= Events_StateChanged;
                    _vlcmedia.Events.DurationChanged -= Events_DurationChanged;
                    _vlcmedia.Dispose();
                }
                _vlcmedia = Vlcfactory.CreateMedia <IMedia>(videoSrcUrl);
                _vlcmedia.Events.StateChanged    += Events_StateChanged;
                _vlcmedia.Events.DurationChanged += Events_DurationChanged;
                // 自定义显示
                _memRender = _vlcplayer.CustomRenderer;
                _memRender.SetFormat(new BitmapFormat(704, 576, ChromaType.RV24));
                _memRender.SetCallback(delegate(Bitmap frame)
                {
                    if ((frame != null) && (ReceiveFrameEvent != null))
                    {
                        if (_videoPlayState)
                        {
                            long currentDateTime = _currentTime;

                            Image imgd             = (Bitmap)frame.Clone();
                            FaceDetectInfo facedet = new FaceDetectInfo(imgd, currentDateTime);

                            //ReceiveFrameEvent(facedet);
                            Task.Factory.StartNew(() => ReceiveFrameEvent(facedet));
                        }
                        frame.Dispose();
                        frame = null;
                    }
                });

                _vlcplayer.Open(_vlcmedia);
                _vlcplayer.Play();
                _videoPlayState = true;

                return(true);
            }
            catch (Exception ex)
            {
                Log4NetHelper.Instance.Error("启动视频播放Capture方法出现错误:" + ex.Message);
                return(false);
            }
        }
Пример #4
0
 private void AcqForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     // TODO: fixed media-related operations cause null reference
     try
     {
         _player.Stop();
         _player.Dispose();
     }
     catch { }
     try
     {
         _media.Dispose();
     }
     catch { }
 }
Пример #5
0
        /// <summary>
        /// Closes the media player and releases all resources.
        /// </summary>
        public void CloseMedia()
        {
            if (_player != null)
            {
                // Close the media player.
                _disk.Stop();
                _disk.Dispose();
                _player.Dispose();
                _media.Dispose();
            }

            _player = null;
            _disk   = null;
            _media  = null;
        }
Пример #6
0
        void DisposePlayer()
        {
            if (_sampleChannel != null)
            {
                _sampleChannel.PreVolumeMeter -= SampleChannelPreVolumeMeter;
                _sampleChannel = null;
            }

            _mMedia.Events.DurationChanged -= EventsDurationChanged;
            _mMedia.Events.StateChanged    -= EventsStateChanged;

            _mPlayer.Stop();

            _mMedia.Dispose();
            _mMedia = null;

            if (_waveProvider != null && _waveProvider.BufferedBytes > 0)
            {
                try
                {
                    _waveProvider.ClearBuffer();
                }
                catch (Exception ex)
                {
                    string m = ex.Message;
                }
            }
            _waveProvider = null;
            Listening     = false;
        }
Пример #7
0
        private void RecordingForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (_ffmpeg != null)
            {
                _ffmpeg.StandardInput.WriteLine("q");
                _ffmpeg.WaitForExit(5000);
                if (!_ffmpeg.HasExited)
                {
                    try
                    {
                        _ffmpeg.Kill();
                    }
                    catch
                    { }
                }
                _ffmpeg.Dispose();
                _ffmpeg = null;

                if (_player.IsPlaying)
                {
                    MessageBox.Show("文件已成功保存为:" + myController.CommonDataPool.VideoPath + '\\' + _start.ToString("yyyyMMddHHmmss"));
                }
            }
            _player.Stop();
            _player.Dispose();
            _media.Dispose();
        }
Пример #8
0
 private void Player_FormClosing(object sender, FormClosingEventArgs e)
 {
     try { m_player.Stop(); } catch
     {
     }
     m_factory.Dispose();
     m_media.Dispose();
     m_player.Dispose();
 }
Пример #9
0
 private void Player_FormClosing(object sender, FormClosingEventArgs e)
 {
     try { _mPlayer.Stop(); } catch
     {
     }
     _mFactory.Dispose();
     _mMedia.Dispose();
     _mPlayer.Dispose();
 }
 private void DisposeMedia()
 {
     if (m_media != null)
     {
         m_media.Events.DurationChanged -= Events_DurationChanged;
         m_media.Events.StateChanged    -= Events_StateChanged;
         m_media.Events.ParsedChanged   -= Events_ParsedChanged;
         m_media.Dispose();
     }
 }
Пример #11
0
        public void Stop()
        {
            if (mMedia == null)
            {
                return;
            }

            IsPlaying = false;
            mPlayer.Stop();
            mMedia.Dispose();
        }
Пример #12
0
 /// <summary>
 /// Disposes of object resources.
 /// </summary>
 /// <param name="disposeManagedResources">If true, managed resources should be
 /// disposed of in addition to unmanaged resources.</param>
 protected virtual void Dispose(bool disposeManagedResources)
 {
     if (disposeManagedResources)
     {
         m_factory.Dispose();
         m_player.Dispose();
         m_equalizer.Dispose();
         m_media.Dispose();
         m_media_preview.Dispose();
         m_memRender.Dispose();
         m_media_list.Dispose();
         m_list_player.Dispose();
         m_media_list_preview.Dispose();
         m_list_preview_player.Dispose();
     }
 }
Пример #13
0
        public void GetDuration(string filePath)
        {
            IMedia       media  = m_factory.CreateMedia <IMediaFromFile>(filePath);
            IVideoPlayer player = m_factory.CreatePlayer <IVideoPlayer>();

            m_memRender = player.CustomRenderer;
            m_memRender.SetFormat(new BitmapFormat(1, 1, ChromaType.RV24));
            media.Events.DurationChanged += new EventHandler <MediaDurationChange>(Events_GetTimeDuration);
            media.Parse(true);
            player.Play();
            player.Stop();

            Thread.Sleep(100);
            player.Dispose();
            m_memRender.Dispose();
            media.Dispose();
        }
Пример #14
0
 private void StopPlayer()
 {
     if (_player != null)
     {
         _player.Stop();
         _player.Dispose();
         _player = null;
     }
     if (_media != null)
     {
         _media.Dispose();
         _media = null;
     }
     if (_factory != null)
     {
         _factory.Dispose();
         _factory = null;
     }
 }
Пример #15
0
        private void DisposeMedia()
        {
            if (_media == null)
            {
                return;
            }
            if (_player.IsPlaying)
            {
                _player.Stop();
            }

            HookMediaEvents(false);
            _media.Dispose();
            _media = null;

            // ReSharper disable once ExplicitCallerInfoArgument
            OnPropertyChanged(nameof(HasAudio));
            Duration = 0.0;
            Position = 0.0;
        }
Пример #16
0
 private void RecordingForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (_ffmpeg != null)
     {
         _ffmpeg.StandardInput.WriteLine("q");
         _ffmpeg.WaitForExit(5000);
         if (!_ffmpeg.HasExited)
         {
             try
             {
                 _ffmpeg.Kill();
             }
             catch
             { }
         }
         _ffmpeg.Dispose();
         _ffmpeg = null;
     }
     _player.Stop();
     _player.Dispose();
     _media.Dispose();
 }
Пример #17
0
        private void DisposePlayer()
        {
            try
            {
                if (_sampleChannel != null)
                {
                    _sampleChannel.PreVolumeMeter -= SampleChannelPreVolumeMeter;
                    _sampleChannel = null;
                }


                _mMedia.Events.DurationChanged -= EventsDurationChanged;
                _mMedia.Events.StateChanged    -= EventsStateChanged;

                _mPlayer.Stop();

                _mMedia.Dispose();
                _mMedia = null;

                if (_waveProvider?.BufferedBytes > 0)
                {
                    try
                    {
                        _waveProvider?.ClearBuffer();
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogExceptionToFile(ex, "VLC");
            }
            _waveProvider = null;

            Listening = false;
        }
Пример #18
0
 private void Player_FormClosing(object sender, FormClosingEventArgs e)
 {
     lock (_lock)
     {
         if (_mPlayer != null)
         {
             try
             {
                 _mPlayer.Stop();
             }
             catch
             {
             }
         }
         try
         {
             if (_mFactory != null)
             {
                 _mFactory.Dispose();
             }
             if (_mMedia != null)
             {
                 _mMedia.Dispose();
             }
             if (_mPlayer != null)
             {
                 _mPlayer.Dispose();
             }
         }
         catch
         {
         }
     }
     if (vNav != null)
     {
         vNav.ReleaseGraph();
     }
 }