/// <summary> /// 在铺满下轮播 /// </summary> /// <param name="vlcControl"></param> /// <param name="rtspStrs"></param> public void Play(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.Play(new Uri(rtspStrs[i])); i++; timer.Tick += (s, e) => { timer.Stop(); string rtspStr = rtspStrs[i % count]; vlcControl.Play(new Uri(rtspStr)); i++; timer.Start(); }; timer.Start(); } catch (Exception) { Playing = false; } }
private void OpenFile(object o) { var path = o.ToString(); FileName = path; if (string.IsNullOrEmpty(path)) { return; } try { ClearPlaylist(); _player.Media = new PathMedia(o.ToString()); _player.Play(); IsPlaying = true; HasChapters = false; } catch (Exception exc) { var message = String.Format("Unable to load file '{0}'.", path); Logger.Instance.Warn(message, exc); MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } OnPropertyChanged("Media"); }
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; } }
public void CommandTogglePlayPause() { if (player.IsPlaying) { player.Pause(); } else { player.Play(); } }
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 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 m_Template_TemplatePlaying(object sender, PlayingEventArgs e) { if (!string.IsNullOrEmpty(streamUrl) && !vlcControl.IsPlaying) { vlcControl.Play(new Uri(streamUrl)); } }
private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { bool flag = profiles != null && combobox.SelectedIndex >= 0; if (flag) { StreamSetup streamSetup = new StreamSetup(); streamSetup.Stream = StreamType.RTPUnicast; streamSetup.Transport = new Transport(); streamSetup.Transport.Protocol = TransportProtocol.RTSP; MediaUri mediaUri = new MediaUri(); mediaUri = mediaClient.GetStreamUri(streamSetup, profiles[combobox.SelectedIndex].token); UriBuilder uriBuilder = new UriBuilder(mediaUri.Uri); uriBuilder.Scheme = "rtsp"; string[] options = new string[] { ":rtsp-http", ":rtsp-http-port=" + uriBuilder.Port.ToString(), ":rtsp-user="******":rtsp-pwd=" + campassword, ":network-caching=300" }; control.Play(uriBuilder.Uri, options); stop_play.IsEnabled = true; playingrui = uriBuilder.Uri; } recordcheckbox.IsEnabled = true; }
public override bool Play(string strFile) { url = strFile; VlcContext.StartupOptions.IgnoreConfig = true; VlcContext.StartupOptions.AddOption("--no-video-title-show"); VlcContext.StartupOptions.AddOption("--http-caching=" + OnlineVideos.MediaPortal1.PluginConfiguration.Instance.wmpbuffer); //VlcContext.StartupOptions.LogOptions.LogInFile = true; //VlcContext.StartupOptions.LogOptions.Verbosity = VlcLogVerbosities.Standard; //VlcContext.StartupOptions.LogOptions.LogInFilePath = Path.Combine(Config.GetFolder(MediaPortal.Configuration.Config.Dir.Log), "vlc-onlinevideos.log"); if (IsInstalled) { VlcContext.LibVlcDllsPath = vlcPath; VlcContext.LibVlcPluginsPath = Path.Combine(vlcPath, "plugins"); } vlcCtrl = new VlcControl(); GUIGraphicsContext.form.Controls.Add(vlcCtrl); vlcCtrl.Enabled = false; vlcCtrl.PositionChanged += vlcCtrl_PositionChanged; vlcCtrl.EncounteredError += vlcCtrl_EncounteredError; media = new PathMedia(strFile); vlcCtrl.Play(media); GUIPropertyManager.SetProperty("#TV.Record.percent3", 0.0f.ToString()); // set to 0, as this player doesn't support download progress reporting GUIWaitCursor.Init(); GUIWaitCursor.Show(); // init and show the wait cursor while buffering return(true); }
private void button1_Click(object sender, EventArgs e) { VlcControl vc = new VlcControl(); Vlc.DotNet.Core.Medias.PathMedia lm = new Vlc.DotNet.Core.Medias.PathMedia(@"[探索频道-重返51区].Discovery.Channel.Return.To.Area.51.PDTV.XviD-HEH.avi"); vc.Play(lm); }
private async Task Play(Channel channel) { var src = await _discoverSvc.GetSource(channel); _currentChannel = channel; _vlcControl.Play(src); }
public VideoPanel() { InitializeComponent(); this.myVlcControl = new Vlc.DotNet.Forms.VlcControl(); ((System.ComponentModel.ISupportInitialize)(this.myVlcControl)).BeginInit(); // // myVlcControl // this.myVlcControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.myVlcControl.BackColor = System.Drawing.SystemColors.ButtonShadow; this.myVlcControl.Location = new System.Drawing.Point(12, 12); this.myVlcControl.Name = "myVlcControl"; this.myVlcControl.Size = new System.Drawing.Size(564, 338); this.myVlcControl.TabIndex = 0; this.myVlcControl.Text = "vlcRincewindControl1"; myVlcControl.Dock = DockStyle.Fill; this.myVlcControl.VlcLibDirectory = null; this.myVlcControl.VlcLibDirectoryNeeded += new System.EventHandler <Vlc.DotNet.Forms.VlcLibDirectoryNeededEventArgs>(this.OnVlcControlNeedLibDirectory); //this.myVlcControl.LengthChanged += new System.EventHandler<Vlc.DotNet.Core.VlcMediaPlayerLengthChangedEventArgs>(this.OnVlcMediaLengthChanged); //this.myVlcControl.Paused += new System.EventHandler<Vlc.DotNet.Core.VlcMediaPlayerPausedEventArgs>(this.OnVlcPaused); //this.myVlcControl.Playing += new System.EventHandler<Vlc.DotNet.Core.VlcMediaPlayerPlayingEventArgs>(this.OnVlcPlaying); //this.myVlcControl.PositionChanged += new System.EventHandler<Vlc.DotNet.Core.VlcMediaPlayerPositionChangedEventArgs>(this.OnVlcPositionChanged); //this.myVlcControl.Stopped += new System.EventHandler<Vlc.DotNet.Core.VlcMediaPlayerStoppedEventArgs>(this.OnVlcStopped); this.Controls.Add(this.myVlcControl); ((System.ComponentModel.ISupportInitialize)(this.myVlcControl)).EndInit(); myVlcControl.Play(new Uri("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi")); }
/// <summary> /// 流媒体播放器开始播放 /// </summary> /// <param name="uri">播放地址</param> public void Play(string uri) { try { if (vlcPlayer != null) { //设置播放地址 LocationMedia media = new LocationMedia(uri); //PathMedia media = new PathMedia(uri); //播放 vlcPlayer.Play(media); } //if (this.vlcPlayer == null) //{ // string pluginPath = System.Environment.CurrentDirectory + "\\plugins\\"; // this.vlcPlayer = new VlcPlayer(pluginPath); //} //this.vlcPlayer.PlayFile(uri); } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } finally { } }
private void TrackBar_MouseUp(object sender, MouseEventArgs e) { if (vlcControl != null) { vlcControl.Position = (Value / 100f); vlcControl.Play(); } }
private void PlayInternal(PlayOptions options) { EnsureMediaPlayerCreated(); CurrentPlaylistIndex = 0; CurrentPlayOptions = options; _playlist = options.Items.ToList(); _isPaused = false; var path = options.Items.First().Path; try { //var media = new PathMedia(@"D:\\Video\\TV\\30 Rock\\Season 1\\30 Rock - 1x02 - The Aftermath.mkv"); var media = path.StartsWith("http", StringComparison.OrdinalIgnoreCase) ? (MediaBase) new LocationMedia(path) : (MediaBase) new PathMedia(path); //media.StateChanged += // delegate(MediaBase s, VlcEventArgs<States> args) // { // if (args.Data == States.Ended) // { // var subItems = media.SubItems; // if (subItems.Count > 0) // { // _vlcControl.Play(subItems[0]); // } // } // }; //media.MediaSubItemAdded += // delegate(MediaBase s, VlcEventArgs<MediaBase> args) // { // _vlcControl.Media = args.Data; // _vlcControl.Play(); // }; _vlcControl = new VlcControl(); _vlcControl.Media = media; _vlcControl.PlaybackMode = PlaybackModes.Loop; _vlcControl.Stopped += _vlcControl_Stopped; _vlcControl.Paused += _vlcControl_Paused; _vlcControl.Playing += _vlcControl_Playing; _vlcControl.Play(); _vlcControl.SetHandle(_hiddenWindow.Form.Handle); _userInput.GlobalKeyDown += _userInput_KeyDown; } catch (Exception ex) { _logger.ErrorException("Error beginning playback", ex); DisposePlayer(); } }
private void button1_Click(object sender, EventArgs e) { Button btn = (Button)sender; VlcControl control = (VlcControl)btn.Tag; VlcMedia media = control.GetCurrentMedia(); if (btn.Text == "Rec.") { control.Stop(); string[] prms = new string[] { ":sout=#duplicate{dst=std{access=file,mux=mp4,dst='" + media.Title.Substring(7).Replace("/", "_").Replace(":", "-") + ".mp4'},dst=display}" }; control.Play(new Uri(media.Mrl), prms); control.Refresh(); btn.Text = "Stop"; } else { control.Stop(); string[] prms = new string[] { "" }; control.Play(new Uri(media.Mrl), prms); btn.Text = "Rec."; } }
/// <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 Play(Uri mediaUri) { lock (_vlcControlLock) { Console.WriteLine($"{ViewModel.Index} {DateTime.Now.ToString(DateTimeFormatInfo.CurrentInfo.FullDateTimePattern)} Playing"); _vlcControl.Stop(); if (mediaUri == null) { return; } _vlcControl.Play(mediaUri); Console.WriteLine($"{ViewModel.Index} {DateTime.Now.ToString(DateTimeFormatInfo.CurrentInfo.FullDateTimePattern)} Play done"); } }
/// <summary> /// Pause/Resume playback on the selected Vlc control /// </summary> /// <param name="vlc">Vlc control to toggle</param> public static void TogglePause(VlcControl vlc) { if (vlc != null) { if (vlc.State == Vlc.DotNet.Core.Interops.Signatures.MediaStates.Paused) { vlc.Play(); log.Debug(string.Format("{0} resume playing", vlc.Name)); } else if (vlc.State == Vlc.DotNet.Core.Interops.Signatures.MediaStates.Playing) { vlc.Pause(); log.Debug(string.Format("{0} pause", vlc.Name)); } } }
public void Play(Control host) { if (!string.IsNullOrEmpty(addr.StreamAddr) && IsLive && !isPlaying) { var fileName = string.Format(@"{0}\{1}.avi", GetDir(), TimeUtil.ToTimestamp(DateTime.Now)); if (File.Exists(fileName)) { File.Delete(fileName); } process = StartRtspRec(fileName); host.Controls[0].Visible = false; host.Controls.Add(player); player.Play(new FileInfo(fileName)); monitor.Watch(this); recPath = fileName; isPlaying = true; } }
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 { } }
private void Play(Uri mediaUri) { //If invoked from the main thread it deadlocks sometimes. Task.Run(() => { lock (_vlcControlLock) { _streamWatchdogTimer.Stop(); _vlcControl.Stop(); if (mediaUri == null) { return; } _vlcControl.Play(mediaUri, "no-audio"); _streamWatchdogTimer.Start(); } }); }
/// <summary> /// 构造函数 /// </summary> public PopupWindow() { InitializeComponent(); //初始化配置,指定引用库 //vlcControl.MediaPlayer.VlcLibDirectoryNeeded += App.OnVlcControlNeedsLibDirectory; //MediaPlayer.MediaPlayer.EndInit(); VlcControl myVlcControl = new VlcControl(); // 创建绑定,绑定Image Binding bing = new Binding { Source = myVlcControl, Path = new PropertyPath("VideoSource") }; MediaPlayer.SetBinding(Image.SourceProperty, bing); myVlcControl.Play(); Loaded += PopupWindow_Loaded; }
public MainWindow() { InitializeComponent(); var control = new VlcControl(); this.WindowsFormsHost.Child = control; var currentAssembly = Assembly.GetEntryAssembly(); var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName; // Default installation path of VideoLAN.LibVLC.Windows var libDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64")); control.BeginInit(); control.VlcLibDirectory = libDirectory; control.EndInit(); control.Play(new Uri("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi")); }
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); }
public void Play(FileItem AFileItem, int APosition) { if (CurrentFile == null || CurrentFile.FileName != AFileItem.FileName) { Program.Logger.Debug("Play: {0} [{1}]", Vlc.Name, AFileItem.StrData()); //Console.WriteLine($"Play ${Name} {AFileItem}"); ThreadPool.QueueUserWorkItem((AData) => Vlc.Play(new FileInfo(AFileItem.FileName))); // Vlc.Play(new FileInfo(AFileItem.FileName)); CurrentFile = AFileItem; } //_logger.Debug("Play: {0} >{1} [{2}]", Vlc.Name, Form1.TimeSpanToString(new TimeSpan(0, 0, 0, APosition)), AFileItem.StrData()); //if (!Vlc.IsPlaying) //{ // Vlc.Play(); //} if (APosition >= 0) { Vlc.Time = APosition; } }
/// <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(); }); }
private static void ReplayMedia(VlcControl oldControl, Form hostForm) { oldControl.Stop(); var timer = new TimerX { Interval = 1 }; ElapsedEventHandler handler = (s, e) => { hostForm.BeginInvoke(new Action(() => { timer.Enabled = false; oldControl.VlcMediaPlayer.Position = 0; oldControl.Play(); })); }; timer.Elapsed += handler; timer.AutoReset = false; timer.Enabled = true; }
/// <summary> /// Uns the pause. /// </summary> /// <returns>Task.</returns> public void UnPause() { _vlcControl.Play(); }