private bool startPlay = false; // If no media was set a file dialog is shown instead when the play button is clicked.. /// <summary> /// Calls the VlcControl.SetMedia() method with the proper internal parameter collection given with the PlayerForm.InitPlayerForm() method's overload. /// <para/>If no media was set (PlayerForm.InitPlayerForm() was not called), the play button justs shows a file dialog to select a file to play. /// </summary> private void SetMedia() { if (file != null) // If the FileInfo overload of the PlayerForm.InitPlayerForm() was called, call the proper VlcControl.SetMedia() method overload.. { vlcControl.SetMedia(file, options); startPlay = true; // indicates that the playback can be started.. } else if (stream != null) // If the Stream overload of the PlayerForm.InitPlayerForm() was called, call the proper VlcControl.SetMedia() method overload.. { vlcControl.SetMedia(stream, options); startPlay = true; // indicates that the playback can be started.. } else if (uri != null) // If the Uri overload of the PlayerForm.InitPlayerForm() was called, call the proper VlcControl.SetMedia() method overload.. { vlcControl.SetMedia(uri, options); startPlay = true; // indicates that the playback can be started.. } else if (mrl != null) // If the mrl string overload of the PlayerForm.InitPlayerForm() was called, call the proper VlcControl.SetMedia() method overload.. { vlcControl.SetMedia(mrl, options); startPlay = true; // indicates that the playback can be started.. } if (startPlay) // If some call to the overloaded PlayerForm.InitPlayerForm() method was made, the playback can be started.. { vlcControl.Play(); SetPlayBackControlsEnabled(); // set the playback controls as enabled after the playback is started.. SetButtonImages(); // set the button images.. vlcControl.Playing += VlcControl_Playing; } }
private static void RecycleVlcControl(VlcControl oldControl, Form hostForm) { oldControl.Stop(); oldControl.ResetMedia(); // hostForm.Controls.Remove(oldControl); // oldControl.Dispose(); var timer = new TimerX { Interval = 1 }; ElapsedEventHandler handler = (s, e) => { hostForm.BeginInvoke(new Action(() => { // CreateVlcControl(hostForm); timer.Enabled = false; oldControl.SetMedia(new FileInfo(source)); oldControl.Play(); })); }; timer.Elapsed += handler; timer.AutoReset = false; timer.Enabled = true; }
private void ShowVideo(FileInfo file) { _vlcControl1.SetMedia(file); _videoView.videoPanel.Controls.Add(_vlcControl1, 0, 0); //Add Vlc control to videoPanel _vlcControl1.Dock = DockStyle.Fill; _vlcControl1.Play(); _vlcControl1.Video.IsMouseInputEnabled = false; _vlcControl1.Video.IsKeyInputEnabled = false; _vlcControl1.MouseClick += new MouseEventHandler(vlcControl1_Click); }
private void SetVideo(songreq request) { try { vlc.Position = 0; var id = YoutubeClient.ParseVideoId(request.ytlink); lblRequester.Text = request.requester; var yt = new YoutubeClient(); var video = yt.GetVideoMediaStreamInfosAsync(id).Result; var muxed = video.Muxed.WithHighestVideoQuality(); lblTitle.Text = GetVideoTitle(request.ytlink); vlc.SetMedia(new Uri(muxed.Url)); vlc.Play(); } catch { } }
public static VlcControl CreateVlcControl(Form hostForm) { var result = new VlcControl() { Location = new Point(0, 0), Size = hostForm.Size, BackColor = Color.FromArgb(110, 110, 110), Dock = DockStyle.Fill, }; result.BeginInit(); LoadVlcConfig(); if (null != _vlcOptions) { result.VlcMediaplayerOptions = _vlcOptions; } result.VlcLibDirectory = new DirectoryInfo(@"libvlc\win-x86"); result.EndInit(); hostForm.Controls.Add(result); result.VlcMediaPlayer.EndReached += (sender, args) => { hostForm.BeginInvoke(new Action(() => { //ReCreateVlcControl( result, hostForm ); //RecycleVlcControl( result, hostForm ); ReplayMedia(result, hostForm); })); }; result.SetMedia(new FileInfo(source)); result.Play(); return(result); }
/// <summary> /// Vaizdo medžiagos gavimas ir atvaizdavimas. /// </summary> /// <param name="vlcControl">Vaizdo grotuvo kontrolė</param> /// <param name="mode">Vaizdo medžiagos rėžimas</param> /// <param name="channel">Kameros ID</param> /// <param name="startTime">Vaizdo įrašo pradžios laikas</param> /// <param name="endTime">Vaizdo įrašo pabaigos laikas</param> public static void PlayVideo(VlcControl vlcControl, VideoMode mode, int channel, DateTime?startTime, DateTime?endTime) { string sourceURL = ""; Settings settings = SettingsController.GetSettings(); switch (mode) { case VideoMode.Stream: sourceURL = string.Format(Properties.Resources.streamURL, settings.NVRUsername, settings.NVRPassword, settings.NVRIP, settings.NVRPort, channel); break; case VideoMode.Recording: string startTimeString = startTime.Value.ToString("yyyyMMddTHHmmssZ"); string endTimeString = endTime.Value.ToString("yyyyMMddTHHmmssZ"); sourceURL = string.Format(Properties.Resources.recordingURL, settings.NVRUsername, settings.NVRPassword, settings.NVRIP, settings.NVRPort, channel, startTimeString, endTimeString); break; } try { var task = Task.Run(() => { vlcControl.SetMedia(new Uri(sourceURL)); vlcControl.Play(); }); if (task.Wait(TimeSpan.FromSeconds(10))) { return; } else { MessageBox.Show(Properties.Strings.errNoVideo, Properties.Strings.errTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show(Properties.Strings.errNoVideo, Properties.Strings.errTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Add one player to the panel asynchronously. /// </summary> /// <returns></returns> private async Task AddPlayerAsync() { await Task.Run(async() => { var player = new VlcControl { VlcLibDirectory = new DirectoryInfo(this.vlcLibraryPath), Size = new Size(200, 200) }; var uiUpdatedTask = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); panel.BeginInvoke((MethodInvoker) delegate { panel.Controls.Add(player); player.EndInit(); uiUpdatedTask.SetResult(true); }); await uiUpdatedTask.Task.ConfigureAwait(false); lock (listOfControls) { // Add to a list listOfControls.Add(player); } HookEvents(player); // If any of the following 2 elements is true, then the vlc player itself will capture input from the user. // and then, the mouse click event won't fire. player.Video.IsMouseInputEnabled = false; player.Video.IsKeyInputEnabled = false; player.Audio.IsMute = true; // Tell the player to play player.SetMedia(textBox1.Text, StreamParams); player.Play(); }); }
void listBox1_MouseDoubleClick(object sender, MouseEventArgs e) { ////////////////////////////////////////////////////////////load media/////////////////////////////////////////////// string chosen = listBox1.SelectedItem.ToString(); string final = selectedpath2 + "\\" + chosen; control.SetMedia(new Uri(final).AbsoluteUri); control.Audio.Volume = 0; control.Update(); ////////////////////////////////////////////////////////////calculate trackbar length/////////////////////////////////////////////// var player = new WindowsMediaPlayer(); var clip = player.newMedia(final); string vOut = clip.duration.ToString(); long howdy = Convert.ToInt64(clip.duration); string vOut2 = vOut.Replace(".", ""); int x = Int32.Parse(vOut2); int x_result = x * 10; trackBar1.Maximum = x_result; trackBar1.Minimum = 0; Console.WriteLine("Track Bar Maximum : " + trackBar1.Maximum); Console.WriteLine("Track Bar Maximum : " + trackBar1.Minimum); Console.WriteLine("Track Tick Frequency : " + trackBar1.TickFrequency); button9.PerformClick(); System.Threading.Thread.Sleep(1000); button8.PerformClick(); trackBar1.Value = 0; Time_update(0); }
/// <summary> /// Loads the provided image and displays it. /// </summary> /// <param name="name">The filename to load.</param> private void LoadImage(string name) { // Stop the current video. if (_vlcControl.IsPlaying) { _vlcControl.Stop(); } // Unload the current image, if there is one. if (_pictureBox.Image != null) { _pictureBox.Image.Dispose(); } // If there is no next image, stop. if (name == null) { _vlcControl.Stop(); _pictureBox.Image = null; Text = "Sort"; return; } var oldLocation = _currentImageLocation; try { _currentImageLocation = Path.Combine(_project.Directory, name); // If it's a video, use VLC. if (_videoFormats.Contains(Path.GetExtension(name).ToLower())) { _vlcControl.SetMedia(new FileInfo(_currentImageLocation)); if (!_vlcControl.IsPlaying) { _vlcControl.Play(); } _vlcControl.Visible = true; _pictureBox.Visible = false; } // Otherwise, use the picture box. else { _pictureBox.Image = Image.FromFile(_currentImageLocation); _vlcControl.Visible = false; _pictureBox.Visible = true; } } catch (OutOfMemoryException e) { // picture box throws out of memory exception when an image isn't valid, for some reason // Return to the previous image. _currentImageLocation = oldLocation; MessageBox.Show( this, "Can't open " + name + ". This might mean it's an invalid image. Check it out.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); return; } Text = "Sort - " + Path.GetFileName(name); }
public void LoadMedia(string path) { Console.WriteLine($"{Name} Loading media {path}!"); // Don't attempt to load the same media that is already loaded, but put the media back to the start. if (path == CurrentMedia) { if (vlcControl != null) { vlcControl.Position = 0f; } return; } FileType fileType = Utilities.GetFileType(path); if (fileType == FileType.Image) { errorMessageTextBox.Hide(); vlcPlayerTableLayoutPanel.Hide(); try { Image img; using (var fs = new FileStream(path, FileMode.Open)) { var ms = new MemoryStream(); fs.CopyTo(ms); ms.Position = 0; // <=== here if (pictureBox.Image != null) { pictureBox.Image.Dispose(); } img = Image.FromStream(ms); pictureBox.Image = img; pictureBox.Show(); pictureBox.Enabled = true; } } catch (Exception e) { ShowErrorMessageBox(e); if (pictureBox.Image != null) { pictureBox.Image.Dispose(); } } } else if (fileType == FileType.Video) { pictureBox.Hide(); errorMessageTextBox.Hide(); try { if (vlcControl != null) { FileInfo fi = new FileInfo(path); ThreadPool.QueueUserWorkItem(_ => { vlcControl.SetMedia(fi, (repeat) ? "input-repeat=4000" : "input-repeat=0"); vlcControl.Play(); vlcControl.Audio.Volume = (int)volumeTrackbar.Value; }); vlcPlayerTableLayoutPanel.Show(); } else { ShowErrorMessageBox("VLC must be located by this program in order to support video playback. This can be configured in the settings."); } } catch (Exception e) { ShowErrorMessageBox(e); } } else { ShowErrorMessageBox($"File format '{Path.GetExtension(path).ToLower()}' not supported."); } CurrentMedia = path; //Invoke((MethodInvoker)delegate { NotifyPropertyChanged(nameof(EnableButtons)); }); NotifyPropertyChanged(nameof(EnableButtons)); }
void OpenNewScreen(int screen) { foreach (UrlPanel urlPanel in Panel_List) { urlPanel.Url = urlPanel.panel.Controls.OfType<TextBox>().ToList()[0].Text; urlPanel.Label = urlPanel.panel.Controls.OfType<TextBox>().ToList()[1].Text; } form3 = new Form(); form3.Controls.Clear(); Screen screenToUse = Screen.AllScreens[screen]; form3.FormBorderStyle = FormBorderStyle.None; form3.Icon = Properties.Resources.DispatchViewer; form3.WindowState = FormWindowState.Maximized; form3.BackColor = Color.Black; form3.FormClosed += new FormClosedEventHandler(Form_Closing); form3.StartPosition = FormStartPosition.Manual; form3.Location = screenToUse.Bounds.Location; ContextMenuStrip menu = new ContextMenuStrip(); menu.Items.Add("Exit"); menu.ItemClicked += Menu_ItemClicked; form3.ContextMenuStrip = menu; int count = 0; int ScreenH = screenToUse.Bounds.Height; int ScreenW = screenToUse.Bounds.Width; int total = Panel_List.Count; int rows = 0; int cols = 0; if (AttemptedCols != 0 & AttemptedRows != 0) { cols = AttemptedCols; rows = AttemptedRows; } else { if (Panel_List.Count == 1) { rows = 1; cols = 1; } else { if (ScreenH < ScreenW) { rows = 2; cols = Convert.ToInt32(Math.Ceiling((decimal)total / 2)); } else { cols = 2; rows = Convert.ToInt32(Math.Ceiling((decimal)total / 2)); } } } try { for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { UrlPanel urlPanel = Panel_List[count]; VlcControl vlcControl = new VlcControl(); vlcControl.BeginInit(); vlcControl.VlcLibDirectory = vlcLibDirectory; vlcControl.VlcMediaplayerOptions = new[] { "-vvv" }; vlcControl.EndInit(); vlcControl.SetMedia(urlPanel.Url); vlcControl.Play(); vlcControl.Enabled = true; vlcControl.Dock = DockStyle.None; vlcControl.Size = new Size(ScreenW / cols, (ScreenH / rows) - 30); vlcControl.Location = new Point((ScreenW / cols) * j, (ScreenH / rows) * i + 30); #region Label Label AddressLabel = new Label { Text = (urlPanel.Label != String.Empty) ? urlPanel.Label : urlPanel.Url, Height = 30, Width = (ScreenW / cols) / 3, Font = new Font(Font.FontFamily, 16), ForeColor = Color.White, Cursor = Cursors.Hand, AutoEllipsis = true, Tag = vlcControl, Location = new Point((ScreenW / cols) * j, (ScreenH / rows) * i) }; AddressLabel.Click += new EventHandler(Label_Clicked); #endregion Button button1 = new Button { Text = "Rec.", BackColor = Color.White, Height = 30, Width = 65, Font = new Font(Font.FontFamily, 10), Location = new Point(AddressLabel.Right + 15, AddressLabel.Location.Y), Tag = vlcControl }; button1.Click += button1_Click; form3.Controls.Add(button1); form3.Controls.Add(AddressLabel); form3.Controls.Add(vlcControl); VlcControlList.Add(vlcControl); count++; } } } catch (Exception) { } form3.Show(); formOpen = true; }