C#使用VLC插件开发播放器小结 | 您所在的位置:网站首页 › 基于vlc的播放器 › C#使用VLC插件开发播放器小结 |
最开始使用WMP(window media player)开发的播放器,可以正常播放暂停! 但是有局限性: 1.视频暂停后,快速定位,画面没有跟新,还停留在暂停的位置 这里我想既然你不主动切换,我把这一帧画面取处理,贴上去,点播放就隐藏,我用FFmpeg命令取帧画面的后,发现很慢,并且随定位的位置增大而越来越慢。遂放弃! 2.没有上一帧和下一帧的功能接口,不满足我的开发要求 采用VLC播放器完美的解决我的问题: 1.设置播放器的position属性后,画面能跟着切换 2.提供了下一帧的接口 这里提示下:vlc提供的视频时长单位时毫秒级别的 VLC简单播放器的开发流程: 第一步:安装VLC.net插件 搜索VlC,安装VLC.DotNet.Forms,会安装关联的其他包 第二步:添加VLC到工具箱: 点击浏览将Vlc.DotNet.Forms.dll添加进来。这样工具箱就会有VLC插件了 第三步:添加VLC播放器,添加DLL依赖 在设计器界面添加VLC播放器,添加事件VlcLibDirectoryNeeded 这里标红的位置是设置VLC依赖文件的位置IntPtr.Size == 4 表示当前程序是32位 x86的 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(@"..\")); else e.VlcLibDirectory = new DirectoryInfo(Path.GetFullPath(@".\libvlc\")); 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.SetMedia(new System.IO.FileInfo(file)); vlcControl1.Play(); vlcControl1.Pause(); 问题:这里我需要实时的获取当前视频播放的进度,但是VLC的Position传递出来的结果并不是实时的。会间隔一段时间,所以实时刷新播放进度的有点卡顿,希望有大佬可以解决! |
CopyRight 2018-2019 实验室设备网 版权所有 |