/// <summary> /// 在自适应下轮播 /// </summary> /// <param name="vlcControl"></param> /// <param name="rtspStrs"></param> public void PlayOnWPF(Vlc.DotNet.Wpf.VlcControl vlcControl, List <string> rtspStrs) { try { Playing = true; timer.Stop(); timer.Interval = TimeSpan.FromSeconds(Math.Max(5, this.Interval)); int i = 0; int count = rtspStrs.Count; vlcControl.SourceProvider.MediaPlayer.Play(new Uri(rtspStrs[i])); i++; timer.Tick += (s, e) => { timer.Stop(); vlcControl.SourceProvider.MediaPlayer.Play(new Uri(rtspStrs[i % count])); i++; timer.Start(); }; timer.Start(); } catch (Exception) { Playing = false; } }
public void reArrange() { cameraCounter = 0; for (int i = 0; i < GridMain.Children.Count; i++) { if (GridMain.Children[i].GetType() == typeof(StackPanel)) { ((StackPanel)GridMain.Children[i]).Margin = new Thickness(134 + (cameraCounter % 4) * (VIDEOW + 10 * 2), 58 + (VIDEOH + 10 * 2 + 100) * (cameraCounter / 4), 0, 0); /// StackPanel0.Margin; ((StackPanel)GridMain.Children[i]).Name = "s" + cameraCounter; Vlc.DotNet.Wpf.VlcControl v = (Vlc.DotNet.Wpf.VlcControl)(((StackPanel)GridMain.Children[i]).Children[0]); TextBox t = (TextBox)(((StackPanel)GridMain.Children[i]).Children[1]); if (v.MediaPlayer.GetCurrentMedia().State == Vlc.DotNet.Core.Interops.Signatures.MediaStates.Playing) { t.Text = "Camera " + cameraCounter + " Ready!!!"; } else { t.Text = "Camera Not Ready!!! State : " + v.MediaPlayer.GetCurrentMedia().State; }; cameraCounter++; } } }
private void OnAction(object sender, RoutedEventArgs e) { var c = 0; for (int i = 0; i < GridMain.Children.Count; i++) { if (GridMain.Children[i].GetType() == typeof(StackPanel)) { if (((StackPanel)GridMain.Children[i]).Children[0].GetType() == typeof(Vlc.DotNet.Wpf.VlcControl)) { Vlc.DotNet.Wpf.VlcControl v = (Vlc.DotNet.Wpf.VlcControl)(((StackPanel)GridMain.Children[i]).Children[0]); string filename = "action" + c.ToString("000") + ".png"; TextBox t = (TextBox)(((StackPanel)GridMain.Children[i]).Children[1]); if (v.MediaPlayer.GetCurrentMedia().State == Vlc.DotNet.Core.Interops.Signatures.MediaStates.Playing) { v.MediaPlayer.TakeSnapshot(captureFolder + filename); t.Text = "Photo capture and save to " + captureFolder + filename + " !!!"; } else { t.Text = "Camera Not Ready!!! State : " + v.MediaPlayer.GetCurrentMedia().State; }; c++; } } } }
public MainWindow() { InitializeComponent(); vlcControl1 = new Vlc.DotNet.Wpf.VlcControl(); vlcControl1.MediaPlayer.BackColor = System.Drawing.Color.Red; vlcControl1.MediaPlayer.VlcLibDirectoryNeeded += MediaPlayer_VlcLibDirectoryNeeded; //vlcControl1.MediaPlayer.VlcLibDirectory = new System.IO.DirectoryInfo(System.IO.Path.Combine(System.Environment.CurrentDirectory, "Vlc\\x86\\")); //vlcControl1. Grid.Children.Add(vlcControl1); vlcControl1.MediaPlayer.Play(new Uri("rtsp://10.195.155.216:8554/CH001.sdp")); }
/// <summary> /// 播放视频流等 /// </summary> /// <param name="border"></param> /// <param name="panelItem"></param> public static void SetBorderChildByVLC(Border border, CameraPanelItem panelItem) { if (border.DataContext is CameraPanelItem oldItem) { border.DataContext = null; border.Child = null; } border.DataContext = panelItem; if (UseWPFControl) { Vlc.DotNet.Wpf.VlcControl vlcControl = new Vlc.DotNet.Wpf.VlcControl(); vlcControl.SourceProvider.CreatePlayer(libDirectory); if (panelItem.RtspStrs.Count > 1) { VLCGroup vlcGroup = new VLCGroup(1, 15); vlcGroup.PlayOnWPF(vlcControl, panelItem.RtspStrs); } else { vlcControl.SourceProvider.MediaPlayer.Play(new Uri(panelItem.RtspStrs[0])); } border.Child = vlcControl; } else { VlcControl vlcControl = new VlcControl(); string ratio = border.ActualWidth + ":" + border.ActualHeight; vlcControl.BeginInit(); vlcControl.VlcLibDirectory = libDirectory; vlcControl.EndInit(); WindowsFormsHost windowsFormsHost = new WindowsFormsHost { Child = vlcControl }; border.Child = windowsFormsHost; vlcControl.Video.FullScreen = true; vlcControl.Video.AspectRatio = ratio; if (panelItem.RtspStrs.Count > 1) { VLCGroup vlcGroup = new VLCGroup(1, 15); vlcGroup.Play(vlcControl, panelItem.RtspStrs); } else { vlcControl.Play(new Uri(panelItem.RtspStrs[0])); } } }
private void MainWindow1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (vlcControl1 != null) { vlcControl1.MediaPlayer.Position = 1f; vlcControl1.MediaPlayer.Stop(); Grid.Children.Remove(vlcControl1); GC.SuppressFinalize(vlcControl1); vlcControl1 = null; Application.Current.Shutdown(); Environment.Exit(0); //vlcControl1.MediaPlayer.Dispose(); //vlcControl1.Dispose(); } }
void timer_Tick(object sender, EventArgs e) { //Call method var c = 0; for (int i = 0; i < GridMain.Children.Count; i++) { if (GridMain.Children[i].GetType() == typeof(StackPanel)) { if (((StackPanel)GridMain.Children[i]).Children[0].GetType() == typeof(Vlc.DotNet.Wpf.VlcControl)) { Vlc.DotNet.Wpf.VlcControl v = (Vlc.DotNet.Wpf.VlcControl)(((StackPanel)GridMain.Children[i]).Children[0]); string filename = "snapshot" + c.ToString("000") + ".png"; TextBox t = (TextBox)(((StackPanel)GridMain.Children[i]).Children[1]); if (v.MediaPlayer.GetCurrentMedia().State == Vlc.DotNet.Core.Interops.Signatures.MediaStates.Playing) { v.MediaPlayer.TakeSnapshot(captureFolder + filename); t.Text = "Photo capture and save to " + captureFolder + filename + " !!!"; } else { t.Text = "Camera Not Ready!!! State : " + v.MediaPlayer.GetCurrentMedia().State; }; c++; } } } //Change the path to location where your images are stored. DirectoryInfo directory = new DirectoryInfo(captureFolder); if (directory != null) { FileInfo[] files = directory.GetFiles(); CombineImages(files); } }
public void AddCamera(string config) { string[] z = config.Split('|'); try { var vlcCamera = new Vlc.DotNet.Wpf.VlcControl(); vlcCamera.MediaPlayer.VlcLibDirectoryNeeded += OnVlcControlNeedsLibDirectory; vlcCamera.MediaPlayer.Log += MediaPlayer_Log; vlcCamera.MediaPlayer.EndInit(); vlcCamera.MediaPlayer.Width = VIDEOW; //// video.MediaPlayer.Width; vlcCamera.MediaPlayer.Height = VIDEOH; /// video.MediaPlayer.Height; vlcCamera.HorizontalAlignment = HorizontalAlignment.Center; var txt = new TextBox(); txt.HorizontalAlignment = HorizontalAlignment.Center; txt.Width = VIDEOW; /// textBox.Width; txt.Height = 35; /// textBox.Height; //// txt.Background = Brushes.Transparent; // some attribute txt.Margin = new Thickness(0, 5, 0, 0); /// StackPanel0.Margin; txt.TextWrapping = TextWrapping.WrapWithOverflow; var but = new Button(); but.HorizontalAlignment = HorizontalAlignment.Center; but.Width = VIDEOW; /// textBox.Width; but.Height = 35; /// textBox.Height; but.Content = "Remove this camera..."; but.Margin = new Thickness(0, 5, 0, 0); /// StackPanel0.Margin; but.Name = "b" + cameraCounter; but.Click += OnDelete; var lab = new Label(); lab.HorizontalAlignment = HorizontalAlignment.Center; lab.Width = VIDEOW; /// textBox.Width; lab.Height = 35; /// textBox.Height; //// txt.Background = Brushes.Transparent; // some attribute lab.Margin = new Thickness(0, 5, 0, 0); /// StackPanel0.Margin; lab.Visibility = Visibility.Collapsed; lab.Content = config; var stk = new StackPanel(); stk.Orientation = Orientation.Vertical; stk.HorizontalAlignment = HorizontalAlignment.Left; stk.VerticalAlignment = VerticalAlignment.Top; stk.Width = VIDEOW + 10 * 2; stk.Height = VIDEOH + 10 * 2 + 100; stk.Children.Add(vlcCamera); stk.Children.Add(txt); stk.Children.Add(but); stk.Children.Add(lab); stk.Margin = new Thickness(134 + (cameraCounter % 6) * (VIDEOW + 10 * 2), 58 + (VIDEOH + 10 * 2 + 100) * (cameraCounter / 6), 0, 0); /// StackPanel0.Margin; stk.Name = "s" + cameraCounter; GridMain.Children.Add(stk); try { string[] xxx = z[0].Split(':'); string portNo = "80"; if (xxx.Length > 1) { portNo = xxx[1]; } ; var uri = z[3]; //// textBox.Text = uri; uri = uri.Replace("http://", "rtsp://"); string[] options = { ":rtsp-http", ":rtsp-http-port=" + portNo, ":rtsp-user="******":rtsp-pwd=" + z[2], }; vlcCamera.MediaPlayer.Play(new Uri(uri), options); int try3 = 6; do { if (vlcCamera.MediaPlayer.GetCurrentMedia().State == Vlc.DotNet.Core.Interops.Signatures.MediaStates.Error) { if (--try3 == 0) { break; } vlcCamera.MediaPlayer.Stop(); vlcCamera.MediaPlayer.Play(new Uri(uri), options); } Thread.Sleep(1000); } while (vlcCamera.MediaPlayer.GetCurrentMedia().State != Vlc.DotNet.Core.Interops.Signatures.MediaStates.Playing); if (vlcCamera.MediaPlayer.GetCurrentMedia().State == Vlc.DotNet.Core.Interops.Signatures.MediaStates.Playing) { txt.Text = "Camera " + cameraCounter + " Ready!!!"; } else { txt.Text = "Camera " + cameraCounter + " Not Ready!!! State : " + vlcCamera.MediaPlayer.GetCurrentMedia().State; }; Thread.Sleep(3000); buttonAction.IsEnabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", System.Windows.MessageBoxButton.OK, MessageBoxImage.Question); /////Console.WriteLine("{0} Second exception caught.", ex.Message ); } Refresh(GridMain); cameraCounter++; buttonAdd.IsEnabled = false; listBox.Items.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", System.Windows.MessageBoxButton.OK, MessageBoxImage.Question); /////Console.WriteLine("{0} Second exception caught.", ex.Message ); } }
private void myVlcControl_Playing(Vlc.DotNet.Wpf.VlcControl sender, Vlc.DotNet.Core.VlcEventArgs <EventArgs> e) { }
private void myVlcControl_Stopped(Vlc.DotNet.Wpf.VlcControl sender, Vlc.DotNet.Core.VlcEventArgs <EventArgs> e) { }