コード例 #1
0
        /// <summary>
        /// Load the media file.
        /// </summary>
        /// <param name="mediaString">The media file to load.</param>
        /// <param name="mediaIndex">The media index type to load.</param>
        private void LoadMedia(string mediaString, int mediaIndex)
        {
            // If a media string has been selected.
            if (!String.IsNullOrEmpty(mediaString))
            {
                try
                {
                    // Create the player.
                    _player            = new MediaPlayerFactory(true);
                    _disk              = _player.CreatePlayer <IDiskPlayer>();
                    _disk.WindowHandle = this.panelMediaDisplay.Handle;

                    _disk.Events.PlayerPositionChanged += new EventHandler <MediaPlayerPositionChanged>(_disk_PlayerPositionChanged);
                    _disk.Events.TimeChanged           += new EventHandler <MediaPlayerTimeChanged>(_disk_TimeChanged);
                    _disk.Events.MediaEnded            += new EventHandler(_disk_MediaEnded);
                    _disk.Events.PlayerStopped         += new EventHandler(_disk_MediaEnded);

                    // The initialisation sync.
                    UISync.Init(this);

                    // Open the correct media type.
                    switch (mediaIndex)
                    {
                    case 0:
                    case 1:
                        // Open the media file.
                        _media = _player.CreateMedia <IMediaFromFile>(mediaString);
                        break;

                    case 2:
                    default:
                        // Open the media file.
                        _media = _player.CreateMedia <IMedia>(mediaString);
                        break;
                    }

                    // Get the duration changed event.
                    _media.Events.DurationChanged += new EventHandler <MediaDurationChange>(_media_DurationChanged);

                    // Open the media.
                    _disk.Open(_media);
                    _media.Parse(true);

                    // Enable controls.
                    EnabledControls(true);
                    _hasClosed     = false;
                    this.AllowDrop = false;
                }
                catch { }
            }
        }
コード例 #2
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBlock1.Text = ofd.FileName;
                m_media         = m_factory.CreateMedia <IMediaFromFile>(ofd.FileName);
                m_media.Events.DurationChanged += new EventHandler <MediaDurationChange>(Events_DurationChanged);
                m_media.Events.StateChanged    += new EventHandler <MediaStateChange>(Events_StateChanged);

                m_player.Open(m_media);
                m_media.Parse(true);
            }
        }
コード例 #3
0
        public void Play(string filename)
        {
            if (InvokeRequired)
            {
                Invoke(new PlayDelegate(Play), filename);
            }
            else
            {
                _needsSize = _filename != filename;
                _filename  = filename;
                _mMedia    = _mFactory.CreateMedia <IMedia>(filename);
                _mMedia.Events.DurationChanged += EventsDurationChanged;
                _mMedia.Events.StateChanged    += EventsStateChanged;
                _mMedia.Events.ParsedChanged   += Events_ParsedChanged;
                _mPlayer.Open(_mMedia);
                _mMedia.Parse(true);

                _mPlayer.Play();

                string[]  parts = filename.Split('\\');
                string    fn    = parts[parts.Length - 1];
                FilesFile ff    =
                    ((MainForm)Owner).GetCameraWindow(ObjectID).FileList.FirstOrDefault(p => p.Filename.EndsWith(fn));
                if (ff != null)
                {
                    vNav.Render(ff);
                }
            }
        }
コード例 #4
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                m_factory = new MediaPlayerFactory(true);
                m_sourcePlayer = m_factory.CreatePlayer<IVideoPlayer>();
                m_sourcePlayer.Mute = false;
                m_sourcePlayer.Volume = 100;

                m_renderPlayer = m_factory.CreatePlayer<IVideoPlayer>();
                m_renderPlayer.WindowHandle = panel1.Handle;

                m_inputMedia = m_factory.CreateMedia<ICompositeMemoryInputMedia>(MediaStrings.IMEM);
                SetupVideoSourceOutput(m_sourcePlayer.CustomRendererEx);
                SetupAudioSourceOutput(m_sourcePlayer.CustomAudioRenderer);

                Predicate<LogMessage> filter = p => p.Level == LogLevel.Warning || p.Level == LogLevel.Error;
                m_factory.SubscribeToLogMessages(log => Console.WriteLine(log.Message), filter);

                Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #5
0
 public void Open(string file)
 {
     mMedia = mPlayerFactory.CreateMedia <IMedia>(file, new string[] { });
     mMedia.Events.StateChanged += MediaStateChange;
     mPlayer.Open(mMedia);
     mMedia.Parse(true);
 }
コード例 #6
0
        private void Open(Uri source)
        {
            DisposeMedia();
            if (source == null)
            {
                return;
            }

            try
            {
                source.VerifyUriExists(OpenTimeOut);

                _media = _factory.CreateMedia <IMedia>(source.ToString());
                HookMediaEvents(true);
                _media.Parse(Async);
                _player.Open(_media);

                Position = 0.0;
                Rate     = 1.0;
            }
            catch (Exception ex)
            {
                Trace.TraceWarning("Could not open source \"{0}\": {1}", source, ex);
                throw new MediaNotFoundException(
                          string.Format(CultureInfo.CurrentCulture, "Could not open audio \"{0}\"", source), ex);
            }
        }
コード例 #7
0
        public void Play(string Filename)
        {
            if (InvokeRequired)
            {
                Invoke(new PlayDelegate(Play), Filename);
            }
            else
            {
                _filename = Filename;
                m_media   = m_factory.CreateMedia <IMedia>(Filename);
                m_media.Events.DurationChanged += new EventHandler <MediaDurationChange>(Events_DurationChanged);
                m_media.Events.StateChanged    += new EventHandler <MediaStateChange>(Events_StateChanged);
                m_media.Events.ParsedChanged   += new EventHandler <MediaParseChange>(Events_ParsedChanged);
                m_player.Open(m_media);
                m_media.Parse(true);

                m_player.Play();
                _needsSize = true;

                string[]  parts = Filename.Split('\\');
                string    fn    = parts[parts.Length - 1];
                FilesFile ff    =
                    ((MainForm)Owner).GetCameraWindow(ObjectID).FileList.FirstOrDefault(p => p.Filename.EndsWith(fn));
                if (ff != null)
                {
                    vNav.Render(ff);
                }
            }
        }
コード例 #8
0
        public void Play(string RTSPstr)
        {
            try
            {
                _rtsp_str = RTSPstr;
                if (isInit == false)
                {
                    Init_nVLC();
                    isInit = true;
                }

                DisposeMedia();

                m_media = m_factory.CreateMedia <IMedia>(RTSPstr);
                m_media.Events.DurationChanged += new EventHandler <MediaDurationChange>(Events_DurationChanged);
                m_media.Events.StateChanged    += new EventHandler <MediaStateChange>(Events_StateChanged);
                m_media.Events.ParsedChanged   += new EventHandler <MediaParseChange>(Events_ParsedChanged);

                m_player.Open(m_media);
                m_media.Parse(true);

                m_player.Stop();
                m_player.Play();

                CheckConnectionTimer.Start();
            }
            catch (Exception Err)
            {
                throw new Exception("Play Faile, Error: " + Err.StackTrace);
            }
        }
コード例 #9
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
     if (ofd.ShowDialog() == true)
     {
         isFromEvent = true;
         System.Windows.Forms.Application.DoEvents();
         filenamef = ofd.FileName;
         m_media   = m_factory.CreateMedia <IMediaFromFile>(filenamef);
         Thread t = new Thread(() =>
         {
             if (m_player.CurrentMedia != null)
             {
                 m_player.CurrentMedia.Dispose();
             }
             //m_media.Events.DurationChanged += new EventHandler<MediaDurationChange>(Events_DurationChanged);
             //m_media.Events.StateChanged += new EventHandler<MediaStateChange>(Events_StateChanged);
             //m_media.Events.ParsedChanged += new EventHandler<MediaParseChange>(Events_ParsedChanged);
             //System.Windows.Forms.Application.DoEvents();
             m_player.Open(m_media);
             //System.Windows.Forms.Application.DoEvents();
             m_media.Parse(true);
             //System.Windows.Forms.Application.DoEvents();
             m_player.Play();
         });
         t.Start();
         //isFromEvent = false;
     }
 }
コード例 #10
0
        public void PlayFile(string path)
        {
            this.imageD3D.Source = this.d3dSource.ImageSource;

            m_media = m_factory.CreateMedia <IMediaFromFile>(path);

            if (_DurationChanged != null)
            {
                m_media.Events.DurationChanged += _DurationChanged;
            }

            m_player.Open(m_media);
            m_media.Parse(false);

            m_player.Play();
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: peerct/nVLC
        private void OpenSourceMedia(string path)
        {
            IMediaFromFile media = m_factory.CreateMedia <IMediaFromFile>(path);

            m_sourcePlayer.Open(media);
            m_sourcePlayer.Play();
            timer.Start();
        }
コード例 #12
0
ファイル: VideoPlayer.cs プロジェクト: smartwell/video_detect
 //播放视频
 public void StartVideo(string name, string password, string Ip)
 {
     try
     {
         string Url = "rtsp://" + name + ":" + password + "@" + Ip;
         m_media = m_factory.CreateMedia <IMedia>(Url);
         m_player.Open(m_media);
         format = new BitmapFormat(panel1.Width, panel1.Height, ChromaType.RV32);
         m_player.CustomRenderer.SetFormat(format);
         callback = new NewFrameEventHandler(display);
         m_player.CustomRenderer.SetCallback(callback);
         m_player.Play();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #13
0
        void getMedia()
        {
            player.Delay = 0;
            IMedia media = factory.CreateMedia <IMedia>("rtsp://" + IP + ":" + RTSP_PORT + "?videoapi=mc&camera=back&h264=1000-15-640-480");

            player.Open(media);

            player.Play();
        }
コード例 #14
0
        private void playvideo(string path)
        {
            m_media = m_factory.CreateMedia <IMediaFromFile>(path);


            m_player.Open(m_media);
            m_media.Parse(true);

            m_player.Play();
        }
コード例 #15
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox1.Text))
            {
                m_media = m_factory.CreateMedia <IMedia>(textBox1.Text);
                m_media.Events.DurationChanged += new EventHandler <MediaDurationChange>(Events_DurationChanged);
                m_media.Events.StateChanged    += new EventHandler <MediaStateChange>(Events_StateChanged);
                m_media.Events.ParsedChanged   += new EventHandler <MediaParseChange>(Events_ParsedChanged);

                m_player.Open(m_media);
                m_media.Parse(true);

                m_player.Play();
            }
            else
            {
                errorProvider1.SetError(textBox1, "Please select media path first !");
            }
        }
コード例 #16
0
        private void Open(string fileName)
        {
            //Dispatcher.Invoke(new Action(() => textBlock1.Text = fileName), DispatcherPriority.DataBind);

            media = playerFactory.CreateMedia <IVlcMediaFromFile>(fileName);
            media.Events.DurationChanged += new EventHandler <MediaDurationChange>(Events_DurationChanged);
            media.Events.StateChanged    += new EventHandler <MediaStateChange>(Events_StateChanged);

            player.Open(media);
            media.Parse(true);
        }
コード例 #17
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);
            }
        }
コード例 #18
0
ファイル: BasicPlayer.cs プロジェクト: Pzkgw/Camera-Support
        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);
        }
コード例 #19
0
ファイル: Form1.cs プロジェクト: peerct/nVLC
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            m_factory      = new MediaPlayerFactory(true);
            m_sourcePlayer = m_factory.CreatePlayer <IVideoPlayer>();
            m_sourcePlayer.Events.PlayerPlaying += new EventHandler(Events_PlayerPlaying);
            m_sourcePlayer.Mute         = true;
            m_renderPlayer              = m_factory.CreatePlayer <IVideoPlayer>();
            m_renderPlayer.WindowHandle = panel1.Handle;
            m_inputMedia = m_factory.CreateMedia <IMemoryInputMedia>(MediaStrings.IMEM);
            SetupOutput(m_sourcePlayer.CustomRendererEx);
        }
コード例 #20
0
ファイル: Form1.cs プロジェクト: Onemann/NDS20_WinPlayer
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            _mFactory = new MediaPlayerFactory(true);
            _mSourcePlayer = _mFactory.CreatePlayer<IVideoPlayer>();
            _mSourcePlayer.Events.PlayerPlaying += new EventHandler(Events_PlayerPlaying);
            _mSourcePlayer.Mute = true;
            _mRenderPlayer = _mFactory.CreatePlayer<IVideoPlayer>();
            _mRenderPlayer.WindowHandle = panel1.Handle;
            _mInputMedia = _mFactory.CreateMedia<IMemoryInputMedia>(MediaStrings.Imem);
            SetupOutput(_mSourcePlayer.CustomRendererEx);
        }
コード例 #21
0
        public void SetDefaultVideoBG(IntPtr handle)
        {
            if (videoDir != string.Empty)
            {
                if (m_media_list_preview.Count() > 0)
                {
                    m_media_list_preview.Clear();
                }

                for (int i = 0; i < videoPath.Length; i++)
                {
                    m_media_preview = m_factory.CreateMedia <IMediaFromFile>(videoPath[i]);
                    m_media_list_preview.Add(m_media_preview);
                }
                m_list_preview_player.InnerPlayer.WindowHandle = handle;
                StopPreviewVideoBG();
                m_media_preview.Parse(true);
                m_list_preview_player.Play();
                // Console.WriteLine(m_media_list_preview.Count);
                // m_list_preview_player.Position = m_list_player.Position;
            }
        }
コード例 #22
0
ファイル: VLCStream.cs プロジェクト: LubyRuffy/sitw_core
        /// <summary>
        /// Start audio source.
        /// </summary>
        ///
        /// <remarks>Starts audio source and return execution to caller. audio source
        /// object creates background thread and notifies about new frames with the
        /// help of <see cref="DataAvailable"/> event.</remarks>
        ///
        /// <exception cref="ArgumentException">audio source is not specified.</exception>
        ///
        public void Start()
        {
            if (!VlcHelper.VlcInstalled)
            {
                return;
            }
            if (!IsRunning)
            {
                // check source
                if (string.IsNullOrEmpty(_source))
                {
                    throw new ArgumentException("Audio source is not specified.");
                }

                DisposePlayer();

                _mFactory = new MediaPlayerFactory(false);

                _mPlayer = _mFactory.CreatePlayer <IVideoPlayer>();
                _mPlayer.Events.PlayerPlaying          += EventsPlayerPlaying;
                _mPlayer.Events.PlayerStopped          += EventsPlayerStopped;
                _mPlayer.Events.PlayerEncounteredError += EventsPlayerEncounteredError;

                string[] args = Arguments.Trim(',').Split(Environment.NewLine.ToCharArray(),
                                                          StringSplitOptions.RemoveEmptyEntries);
                List <String> inargs = args.ToList();
                inargs.Add(":sout=#transcode{vcodec=none}:Display");

                _mMedia = _mFactory.CreateMedia <IMedia>(_source, inargs.ToArray());

                _mPlayer.Open(_mMedia);

                GC.KeepAlive(_mFactory);
                GC.KeepAlive(_mPlayer);
                GC.KeepAlive(_mMedia);

                _needsSetup = true;
                var fc = new Func <SoundFormat, SoundFormat>(SoundFormatCallback);
                _mPlayer.CustomAudioRenderer.SetFormatCallback(fc);
                //.SetFormat(new SoundFormat(SoundType.S16N, RecordingFormat.SampleRate, RecordingFormat.Channels)));
                var ac = new AudioCallbacks {
                    SoundCallback = SoundCallback
                };
                _mPlayer.CustomAudioRenderer.SetCallbacks(ac);

                _mMedia.Parse(false);


                _mPlayer.Play();
            }
        }
コード例 #23
0
        /// <summary>
        /// Start video source.
        /// </summary>
        ///
        /// <remarks>Starts video source and return execution to caller. Video source
        /// object creates background thread and notifies about new frames with the
        /// help of <see cref="NewFrame"/> event.</remarks>
        ///
        /// <exception cref="ArgumentException">Video source is not specified.</exception>
        ///
        public void Start()
        {
            if (!VlcHelper.VlcInstalled)
            {
                return;
            }
            Isstopping = false;
            if (!IsRunning && !_starting)
            {
                _starting = true;
                // check source
                if (string.IsNullOrEmpty(_source))
                {
                    throw new ArgumentException("Video source is not specified.");
                }

                DisposePlayer();

                _mFactory = new MediaPlayerFactory(false);

                _mPlayer = _mFactory.CreatePlayer <IVideoPlayer>();
                _mPlayer.Events.PlayerPlaying          += EventsPlayerPlaying;
                _mPlayer.Events.PlayerStopped          += EventsPlayerStopped;
                _mPlayer.Events.PlayerEncounteredError += EventsPlayerEncounteredError;


                _mMedia = _mFactory.CreateMedia <IMedia>(_source, Arguments);
                _mPlayer.Open(_mMedia);
                GC.KeepAlive(_mFactory);
                GC.KeepAlive(_mPlayer);
                GC.KeepAlive(_mMedia);

                _needsSetup = true;
                var fc = new Func <SoundFormat, SoundFormat>(SoundFormatCallback);
                _mPlayer.CustomAudioRenderer.SetFormatCallback(fc);
                var ac = new AudioCallbacks {
                    SoundCallback = SoundCallback
                };
                _mPlayer.CustomAudioRenderer.SetCallbacks(ac);


                _mPlayer.CustomRenderer.SetFormat(new BitmapFormat(FormatWidth, FormatHeight, ChromaType.RV24));
                _mPlayer.CustomRenderer.SetCallback(FrameCallback);

                _mMedia.Parse(true);
                _framesReceived = 0;
                _mPlayer.Play();
            }
        }
コード例 #24
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if (m_player != null)
                {
                    m_player.StopAsync();
                }
                SafeDispose(m_media);
                m_media = m_factory.CreateMedia <IMediaFromFile>(ofd.FileName);
                m_player.Open(m_media);
                m_player.Play();
            }
        }
コード例 #25
0
ファイル: Subframe.cs プロジェクト: Onemann/NDS20_WinPlayer
        public Subframe(JsonObject paramSchedule)
        {
            InitializeComponent();

            JsonObjectCollection col = (JsonObjectCollection)paramSchedule;
            frameInfoStrc frameInfo = new frameInfoStrc();

            frameInfo.xPos = int.Parse(col["xPos"].GetValue().ToString());
            frameInfo.yPos = int.Parse(col["yPos"].GetValue().ToString());
            frameInfo.width = int.Parse(col["width"].GetValue().ToString());
            frameInfo.height = int.Parse(col["height"].GetValue().ToString());
            frameInfo.contentsFileName = (string)col["fileName"].GetValue();
            frameInfo.mute = bool.Parse(col["mute"].GetValue().ToString());

            if (frameInfo.width == 0)
            {
                this.WindowState = FormWindowState.Maximized;
            }
            else
            {
                this.Width = frameInfo.width;
                this.Height = frameInfo.height;

            }
            this.Location = new System.Drawing.Point(frameInfo.xPos, frameInfo.yPos);

            # region ==== Create Player ====
            m_factory = new MediaPlayerFactory(true);
            m_player = m_factory.CreatePlayer<IDiskPlayer>();
            m_player.AspectRatio = AspectRatioMode.Default;
            m_player.Mute = frameInfo.mute;

            m_player.WindowHandle = this.pnlPlayerBack.Handle;

            UISync.Init(this);
            #endregion ======================

            #region ==== Contents play ====
            FileInfo contentsFileInfo = new FileInfo(@frameInfo.contentsFileName);
            m_media = m_factory.CreateMedia<IMediaFromFile>(contentsFileInfo.FullName);

            m_player.Open(m_media);
            m_media.Parse(true);

            m_player.Play();
            #endregion =====================
        }
コード例 #26
0
        public VlcPlayer()
        {
            InitializeComponent();


            System.Windows.Forms.Panel p = new System.Windows.Forms.Panel();

            p.BackColor = System.Drawing.Color.Transparent;
            windowsFormsHost1.Opacity = 0.5;
            windowsFormsHost1.Child   = p;


            m_factory = new MediaPlayerFactory(true);
            m_player  = m_factory.CreatePlayer <IVideoPlayer>();

            m_media = m_factory.CreateMedia <IMediaFromFile>(@"E:\Render Library\Movie paths\Dance+SFS2.avi");
            // m_media.Events.DurationChanged += new EventHandler<MediaDurationChange>(Events_DurationChanged);
            //m_media.Events.StateChanged += new EventHandler<MediaStateChange>(Events_StateChanged);

            m_player.Open(m_media);
            m_media.Parse(true);
            m_player.Play();
        }
コード例 #27
0
        //播放视频
        public void StartVideo(string name, string password, string Ip)
        {
            try
            {
                string Url = "rtsp://*****:*****@192.168.23.64";//
                //string Url = "rtsp://" + name + ":" + password + "@" + Ip;
                m_media = m_factory.CreateMedia <IMedia>(Url);
                m_player.Open(m_media);
                format = new BitmapFormat(pictureBox1.Width, pictureBox1.Height, ChromaType.RV32);
                m_player.CustomRenderer.SetFormat(format);
                callback = new NewFrameEventHandler(display);
                m_player.CustomRenderer.SetCallback(callback);
                m_player.Play();

                if (IsPlaying())
                {
                    MessageBox.Show("网络源视频启动成功!", "提示");

                    #region

                    this.button_Detect.Enabled      = true;
                    this.Button_Detect_Stop.Enabled = false;
                    this.button_Camera_Open.Enabled = false;


                    #endregion
                }
                else
                {
                    MessageBox.Show("网络源视频启动失败!", "提示");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #28
0
ファイル: MainSend.cs プロジェクト: Pzkgw/Camera-Support
        public MainSend()
        {
            _mFactory = new MediaPlayerFactory(opt,//new string[] { },
                                               @"C:\Program Files (x86)\VideoLAN\VLC", true, new CLogger());

            InputMedia = _mFactory.CreateMedia <IMemoryInputMedia>(MediaStrings.IMEM);

            Player = _mFactory.CreatePlayer <IVideoPlayer>();


            Player.Events.PlayerPlaying += new EventHandler(Events_PlayerPlaying);

            /*
             * //DateTime _dt;
             *
             * for (int i = 0; i < 2; i++)//while (true)
             * {
             * //_dt = DateTime.Now;
             *
             * if (started) ToggleRunningMedia(false);
             *
             * //_dt = DateTime.Now;
             * //Console.WriteLine(string.Format(" {0:00}:{1:00}:{2:00}.{3:000}    {4}",
             * //   _dt.Hour, _dt.Minute, _dt.Second, _dt.Millisecond, "Stop"));
             *
             *
             *
             *
             ++si;                if (si >= s.Length) si = 0;
             * //_dt = DateTime.Now;
             * //Console.WriteLine(string.Format(" {0:00}:{1:00}:{2:00}.{3:000}    {4}{5}",
             * //_dt.Hour, _dt.Minute, _dt.Second, _dt.Millisecond, "Start", Environment.NewLine));
             *
             * started = true;
             * }*/
        }
コード例 #29
0
ファイル: PlayerForm.cs プロジェクト: zhyinty/CrazyKTVSongMgr
        public PlayerForm(Form ParentForm, List <string> PlayerSongInfoList)
        {
            InitializeComponent();

            this.Owner         = ParentForm;
            SongId             = PlayerSongInfoList[0];
            SongLang           = PlayerSongInfoList[1];
            SongSinger         = PlayerSongInfoList[2];
            SongSongName       = PlayerSongInfoList[3];
            SongTrack          = PlayerSongInfoList[4];
            SongFilePath       = PlayerSongInfoList[5];
            dvRowIndex         = PlayerSongInfoList[6];
            UpdateDataGridView = PlayerSongInfoList[7];

            this.Text = "【" + SongLang + "】" + SongSinger + " - " + SongSongName;

            m_factory             = new MediaPlayerFactory(true);
            m_player              = m_factory.CreatePlayer <IDiskPlayer>();
            m_player.WindowHandle = Player_Panel.Handle;

            Player_ProgressTrackBar.ProgressBarValue = 0;
            Player_ProgressTrackBar.TrackBarValue    = 0;

            m_media = m_factory.CreateMedia <IMediaFromFile>(SongFilePath);
            m_player.Open(m_media);
            m_media.Parse(true);
            m_player.Mute = true;
            m_player.Play();

            Thread.Sleep(1000);

            bool WaitTrackInfo = false;

            while (!WaitTrackInfo)
            {
                if (m_player.AudioTrackCount > 1)
                {
                    foreach (Declarations.TrackDescription TrackDesc in m_player.AudioTracksInfo)
                    {
                        if (TrackDesc.Id != -1)
                        {
                            WaitTrackInfo = true;
                        }
                    }
                }
            }

            List <int> TrackIdList = new List <int>();

            foreach (Declarations.TrackDescription TrackDesc in m_player.AudioTracksInfo)
            {
                TrackIdList.Add(TrackDesc.Id);
            }

            if (TrackIdList.Count > 2)
            {
                switch (SongTrack)
                {
                case "1":
                    if (m_player.AudioTrack != TrackIdList[1])
                    {
                        m_player.AudioTrack = TrackIdList[1];
                    }
                    break;

                case "2":
                    if (m_player.AudioTrack != TrackIdList[2])
                    {
                        m_player.AudioTrack = TrackIdList[2];
                    }
                    break;
                }
                Player_CurrentChannelValue_Label.Text = (TrackIdList.IndexOf(m_player.AudioTrack) == Convert.ToInt32(SongTrack)) ? "伴唱" : "人聲";
            }
            else
            {
                string ChannelValue = "";
                switch (SongTrack)
                {
                case "1":
                    if (m_player.Channel != AudioChannelType.Left)
                    {
                        m_player.Channel = AudioChannelType.Left;
                    }
                    ChannelValue = "1";
                    break;

                case "2":
                    if (m_player.Channel != AudioChannelType.Right)
                    {
                        m_player.Channel = AudioChannelType.Right;
                    }
                    ChannelValue = "2";
                    break;
                }
                Player_CurrentChannelValue_Label.Text = (ChannelValue == SongTrack) ? "伴唱" : "人聲";
            }

            m_player.Events.PlayerPositionChanged += new EventHandler <MediaPlayerPositionChanged>(Events_PlayerPositionChanged);

            m_player.Position = 0;
            m_player.Mute     = false;

            timer.Tick    += new EventHandler(timer_Tick);
            timer.Interval = 500;
            timer.Start();
        }
コード例 #30
0
        private void WorkerThread()
        {
            bool file = false;

            try
            {
                if (File.Exists(_source))
                {
                    file = true;
                }
            }
            catch
            {
            }



            if (_mFactory == null)
            {
                var args = new List <string>
                {
                    "-I",
                    "dumy",
                    "--ignore-config",
                    "--no-osd",
                    "--disable-screensaver",
                    "--plugin-path=./plugins"
                };
                if (file)
                {
                    args.Add("--file-caching=3000");
                }
                try
                {
                    var l2 = args.ToList();
                    l2.AddRange(_arguments);

                    l2        = l2.Distinct().ToList();
                    _mFactory = new MediaPlayerFactory(l2.ToArray());
                }
                catch (Exception ex)
                {
                    MainForm.LogExceptionToFile(ex);
                    MainForm.LogMessageToFile("VLC arguments are: " + String.Join(",", args.ToArray()));
                    MainForm.LogMessageToFile("Using default VLC configuration.");
                    _mFactory = new MediaPlayerFactory(args.ToArray());
                }
                GC.KeepAlive(_mFactory);
            }

            if (file)
            {
                _mMedia = _mFactory.CreateMedia <IMediaFromFile>(_source);
            }
            else
            {
                _mMedia = _mFactory.CreateMedia <IMedia>(_source);
            }

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

            if (_mPlayer != null)
            {
                try
                {
                    _mPlayer.Dispose();
                }
                catch
                {
                }
                _mPlayer = null;
            }


            _mPlayer = _mFactory.CreatePlayer <IVideoPlayer>();
            _mPlayer.Events.TimeChanged += EventsTimeChanged;

            var fc = new Func <SoundFormat, SoundFormat>(SoundFormatCallback);

            _mPlayer.CustomAudioRenderer.SetFormatCallback(fc);
            var ac = new AudioCallbacks {
                SoundCallback = SoundCallback
            };

            _mPlayer.CustomAudioRenderer.SetCallbacks(ac);
            _mPlayer.CustomAudioRenderer.SetExceptionHandler(Handler);

            _mPlayer.CustomRenderer.SetCallback(FrameCallback);
            _mPlayer.CustomRenderer.SetExceptionHandler(Handler);
            GC.KeepAlive(_mPlayer);

            _needsSetup = true;
            _stopping   = false;
            _mPlayer.CustomRenderer.SetFormat(new BitmapFormat(FormatWidth, FormatHeight, ChromaType.RV24));
            _mPlayer.Open(_mMedia);
            _mMedia.Parse(true);

            _mPlayer.Delay = 0;

            _framesReceived = 0;
            Duration        = Time = 0;
            LastFrame       = DateTime.MinValue;


            //check if file source (isseekable in _mPlayer is not reliable)
            Seekable = false;
            try
            {
                var p = Path.GetFullPath(_mMedia.Input);
                Seekable = !String.IsNullOrEmpty(p);
            }
            catch (Exception)
            {
                Seekable = false;
            }
            _mPlayer.WindowHandle = IntPtr.Zero;
            _mPlayer.Play();



            _stopEvent.WaitOne();

            if (!Seekable && !_stopRequested)
            {
                if (PlayingFinished != null)
                {
                    PlayingFinished(this, ReasonToFinishPlaying.DeviceLost);
                }
                if (AudioFinished != null)
                {
                    AudioFinished(this, ReasonToFinishPlaying.DeviceLost);
                }
            }
            else
            {
                if (PlayingFinished != null)
                {
                    PlayingFinished(this, ReasonToFinishPlaying.StoppedByUser);
                }
                if (AudioFinished != null)
                {
                    AudioFinished(this, ReasonToFinishPlaying.StoppedByUser);
                }
            }

            DisposePlayer();
        }
コード例 #31
0
ファイル: PlayerVLC.cs プロジェクト: Sirendium/IQ-RVS
        public void Play(string filename, string titleText)
        {
            if (InvokeRequired)
            {
                Invoke(new PlayDelegate(Play), filename, titleText);
            }
            else
            {
                if (!File.Exists(filename))
                {
                    MessageBox.Show(this, LocRm.GetString("FileNotFound") + Environment.NewLine + filename);
                    return;
                }
                _needsSize = _filename != filename;
                _filename  = filename;
                lock (_lock)
                {
                    _mMedia = _mFactory.CreateMedia <IMediaFromFile>(filename);
                    _mMedia.Events.DurationChanged += EventsDurationChanged;
                    _mMedia.Events.StateChanged    += EventsStateChanged;
                    _mMedia.Events.ParsedChanged   += Events_ParsedChanged;
                    try
                    {
                        _mPlayer.Open(_mMedia);
                        _mMedia.Parse(true);
                    }
                    catch (Exception ex)
                    {
                        Logger.LogException(ex);
                        MessageBox.Show(this, LocRm.GetString("CouldNotOpen") + Environment.NewLine + filename);
                        return;
                    }

                    _mPlayer.Play();
                }

                string[]  parts = filename.Split('\\');
                string    fn    = parts[parts.Length - 1];
                FilesFile ff    = null;
                if (fn.EndsWith(".mp3") || fn.EndsWith(".wav"))
                {
                    var vl = ((MainForm)Owner).GetVolumeLevel(ObjectID);
                    if (vl != null)
                    {
                        ff = vl.FileList.FirstOrDefault(p => p.Filename.EndsWith(fn));
                    }
                    vNav.IsAudio             = true;
                    pnlMovie.BackgroundImage = Properties.Resources.ispy1audio;
                }
                else
                {
                    var cw = ((MainForm)Owner).GetCameraWindow(ObjectID);
                    if (cw != null)
                    {
                        ff = cw.FileList.FirstOrDefault(p => p.Filename.EndsWith(fn));
                    }
                    vNav.IsAudio             = false;
                    pnlMovie.BackgroundImage = Properties.Resources.ispy1;
                }

                if (ff != null)
                {
                    vNav.Init(ff);
                }
                Text = titleText;
            }
        }
コード例 #32
0
ファイル: VLCStream.cs プロジェクト: vmail/main
        /// <summary>
        /// Start video source.
        /// </summary>
        /// 
        /// <remarks>Starts video source and return execution to caller. Video source
        /// object creates background thread and notifies about new frames with the
        /// help of <see cref="NewFrame"/> event.</remarks>
        /// 
        /// <exception cref="ArgumentException">Video source is not specified.</exception>
        /// 
        public void Start()
        {
            if (!VlcHelper.VlcInstalled)
                return;
            Isstopping = false;
            if (!IsRunning && !_starting)
            {
                _starting = true;
                // check source
                if (string.IsNullOrEmpty(_source))
                    throw new ArgumentException("Video source is not specified.");

                DisposePlayer();

                _mFactory = new MediaPlayerFactory(false);

                _mPlayer = _mFactory.CreatePlayer<IVideoPlayer>();
                _mPlayer.Events.PlayerPlaying += EventsPlayerPlaying;
                _mPlayer.Events.PlayerStopped += EventsPlayerStopped;
                _mPlayer.Events.PlayerEncounteredError += EventsPlayerEncounteredError;

                _mMedia = _mFactory.CreateMedia<IMedia>(_source, Arguments);
                _mPlayer.Open(_mMedia);
                GC.KeepAlive(_mFactory);
                GC.KeepAlive(_mPlayer);
                GC.KeepAlive(_mMedia);

                _needsSetup = true;
                var fc = new Func<SoundFormat, SoundFormat>(SoundFormatCallback);
                _mPlayer.CustomAudioRenderer.SetFormatCallback(fc);
                var ac = new AudioCallbacks { SoundCallback = SoundCallback };
                _mPlayer.CustomAudioRenderer.SetCallbacks(ac);

                _mPlayer.CustomRenderer.SetFormat(new BitmapFormat(FormatWidth, FormatHeight, ChromaType.RV24));
                _mPlayer.CustomRenderer.SetCallback(FrameCallback);

                _mMedia.Parse(true);
                _framesReceived = 0;
                _mPlayer.Play();
            }
        }
コード例 #33
0
ファイル: VLCStream.cs プロジェクト: mrgoodman2014/iSpy
        private void WorkerThread()
        {
            bool file = false;

            try
            {
                if (File.Exists(Source))
                {
                    file = true;
                }
            }
            catch
            {
                // ignored
            }

            if (_mFactory == null)
            {
                var args = new List <string>
                {
                    "-I",
                    "dumy",
                    "--ignore-config",
                    "--no-osd",
                    "--disable-screensaver",
                    "--plugin-path=./plugins"
                };
                if (file)
                {
                    args.Add("--file-caching=3000");
                }
                try
                {
                    var l2 = args.ToList();
                    l2.AddRange(_arguments);

                    l2        = l2.Distinct().ToList();
                    _mFactory = new MediaPlayerFactory(l2.ToArray());
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex, "VLC Stream");
                    Logger.LogMessage("VLC arguments are: " + string.Join(",", args.ToArray()), "VLC Stream");
                    Logger.LogMessage("Using default VLC configuration.", "VLC Stream");
                    _mFactory = new MediaPlayerFactory(args.ToArray());
                }
                GC.KeepAlive(_mFactory);
            }

            var vss = Source;

            if (!_modeAudio)
            {
                vss = Tokenise(vss);
            }

            _mMedia = file ? _mFactory.CreateMedia <IMediaFromFile>(vss) : _mFactory.CreateMedia <IMedia>(vss);

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

            if (_mPlayer != null)
            {
                try
                {
                    _mPlayer?.Dispose();
                }
                catch
                {
                    // ignored
                }
                _mPlayer = null;
            }


            _mPlayer = _mFactory.CreatePlayer <IVideoPlayer>();
            _mPlayer.Events.TimeChanged += EventsTimeChanged;

            var fc = new Func <SoundFormat, SoundFormat>(SoundFormatCallback);

            _mPlayer.CustomAudioRenderer.SetFormatCallback(fc);
            var ac = new AudioCallbacks {
                SoundCallback = SoundCallback
            };

            _mPlayer.CustomAudioRenderer.SetCallbacks(ac);
            _mPlayer.CustomAudioRenderer.SetExceptionHandler(Handler);

            if (!_modeAudio)
            {
                _mPlayer.CustomRenderer.SetCallback(FrameCallback);
                _mPlayer.CustomRenderer.SetExceptionHandler(Handler);
            }
            GC.KeepAlive(_mPlayer);

            _needsSetup = true;
            _mPlayer.CustomRenderer.SetFormat(new BitmapFormat(_source.settings.vlcWidth, _source.settings.vlcHeight, ChromaType.RV24));
            _mPlayer.Open(_mMedia);
            _mMedia.Parse(true);

            _mPlayer.Delay = 0;

            Duration  = Time = 0;
            LastFrame = DateTime.MinValue;


            //check if file source (isseekable in _mPlayer is not reliable)
            Seekable = false;
            try
            {
                var p = Path.GetFullPath(_mMedia.Input);
                Seekable = !string.IsNullOrEmpty(p);
            }
            catch (Exception)
            {
                Seekable = false;
            }
            _mPlayer.WindowHandle = IntPtr.Zero;

            _videoQueue = new ConcurrentQueue <Bitmap>();
            _audioQueue = new ConcurrentQueue <byte[]>();


            _mPlayer.Play();
            _abort = new ManualResetEvent(false);
            EventManager();

            if (Seekable)
            {
                PlayingFinished?.Invoke(this, new PlayingFinishedEventArgs(ReasonToFinishPlaying.StoppedByUser));
                AudioFinished?.Invoke(this, new PlayingFinishedEventArgs(ReasonToFinishPlaying.StoppedByUser));
            }
            else
            {
                PlayingFinished?.Invoke(this, new PlayingFinishedEventArgs(_res));
                AudioFinished?.Invoke(this, new PlayingFinishedEventArgs(_res));
            }

            DisposePlayer();
            _abort.Close();
        }
コード例 #34
0
ファイル: VLCStream.cs プロジェクト: vmail/main
        /// <summary>
        /// Start audio source.
        /// </summary>
        /// 
        /// <remarks>Starts audio source and return execution to caller. audio source
        /// object creates background thread and notifies about new frames with the
        /// help of <see cref="DataAvailable"/> event.</remarks>
        /// 
        /// <exception cref="ArgumentException">audio source is not specified.</exception>
        /// 
        public void Start()
        {
            if (!VlcHelper.VlcInstalled)
                return;
            if (!IsRunning)
            {
                // check source
                if (string.IsNullOrEmpty(_source))
                    throw new ArgumentException("Audio source is not specified.");

                DisposePlayer();

                _mFactory = new MediaPlayerFactory(false);

                _mPlayer = _mFactory.CreatePlayer<IVideoPlayer>();
                _mPlayer.Events.PlayerPlaying += EventsPlayerPlaying;
                _mPlayer.Events.PlayerStopped += EventsPlayerStopped;
                _mPlayer.Events.PlayerEncounteredError += EventsPlayerEncounteredError;

                string[] args = Arguments.Trim(',').Split(Environment.NewLine.ToCharArray(),
                                                                                StringSplitOptions.RemoveEmptyEntries);
                List<String> inargs = args.ToList();
                inargs.Add(":sout=#transcode{vcodec=none}:Display");

                _mMedia = _mFactory.CreateMedia<IMedia>(_source, inargs.ToArray());

                _mPlayer.Open(_mMedia);

                GC.KeepAlive(_mFactory);
                GC.KeepAlive(_mPlayer);
                GC.KeepAlive(_mMedia);

                _needsSetup = true;
                var fc = new Func<SoundFormat, SoundFormat>(SoundFormatCallback);
                _mPlayer.CustomAudioRenderer.SetFormatCallback(fc);
                var ac = new AudioCallbacks {SoundCallback = SoundCallback};
                _mPlayer.CustomAudioRenderer.SetCallbacks(ac);
                _mMedia.Events.ParsedChanged += EventsParsedChanged;
                _mMedia.Parse(true);

                _mPlayer.Play();

            }
        }