winform 通过vlccontrol实现海康视频的播放,实现全屏
新建项目,本人的 visualstudio版本是2019,选择的是.net framework这个,core好像不行,不过我看好像有core版本的:
第一步:nuget下载对应的包,就下面这五个。
第二部:导入组件
右键属性,获取dll文件地址,ctrl+c;
右键工具箱,点击选择项
选择dll文件,打开便将其添加到工具箱内,和其他组件一样可以进行拖拽拉升等操作。
第三步:给vlcontrol 组件添加 VlcLibDirectoryNeeded事件(必须操作,右键属性,选择方法,在最下方,双击添加)
private void vlcControl1_VlcLibDirectoryNeeded(object sender, Vlc.DotNet.Forms.VlcLibDirectoryNeededEventArgs e) { var currentAssembly = Assembly.GetEntryAssembly(); var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName; if (currentDirectory == null) return; if (IntPtr.Size == 4) e.VlcLibDirectory = new DirectoryInfo(Path.GetFullPath(@".\libvlc\win-x86\")); else e.VlcLibDirectory = new DirectoryInfo(Path.GetFullPath(@".\libvlc\win-x64\")); if (!e.VlcLibDirectory.Exists) { var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); folderBrowserDialog.Description = "Select Vlc libraries folder."; folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop; folderBrowserDialog.ShowNewFolderButton = true; if (folderBrowserDialog.ShowDialog() == DialogResult.OK) { e.VlcLibDirectory = new DirectoryInfo(folderBrowserDialog.SelectedPath); } } }
第四步:播放视频
vlcControl1.Play("http://**************/******.flv");//只能播放网络流视频 vlcControl1.SetMedia(new System.IO.FileInfo(@"g:\家庭教师.avi"));//本地视频 vlcControl1.Play();
基本的视频播放便已经结束。
第五步:实现双击全屏
问题存在:1:vlccontrol.video.fullScreen=true。这个玩意儿不生效。
bool fullScren=true;
if (fullScreen) { vlcControl1.Dock = DockStyle.None; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable; this.WindowState = System.Windows.Forms.FormWindowState.Normal; fullScreen = false; } else { vlcControl1.Dock = DockStyle.Fill; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; fullScreen = true; }
2:vlccontrol鼠标事件触发问题
private void Form1_Load(object sender, EventArgs e) { vlcControl1.SetMedia(new System.IO.FileInfo(@"g:\家庭教师.avi"));//本地视频
vlcControl1.Play();
vlcControl1.Video.IsMouseInputEnabled = false; vlcControl1.Video.IsKeyInputEnabled = false; // 这行代码最重要
}
然后便可以实现双击全屏之类的操作了
第六步:播放海康视频流
string ip = textBox1.Text; string admin = textBox2.Text; string password = textBox3.Text; if (ip == "") { MessageBox.Show("IP为空,请输入"); return; } if (admin == "") { MessageBox.Show("用户名为空,请输入"); return; } if (password == "") { MessageBox.Show("密码为空,请输入"); return; } string path = "rtsp://" + admin + ":" + password + "@" + ip + ":554/h264/main/sub/av_stream"; vlcControl1.Play(path);
textbox 设置为password那种样式:右键textbox1->属性:PasswordChar:*
关于进度条那些目前还在探索ing