首先感谢 https://*.com/questions/38326003/how-to-remove-a-delay-in-a-streaming-app 的说明
public Form1()
{
InitializeComponent();
vlcControl1 = new Vlc.DotNet.Forms.VlcControl();
this.vlcControl1.Location = new System.Drawing.Point(225, 65);
this.vlcControl1.Name = "vlcControl1";
this.vlcControl1.Size = new System.Drawing.Size(900, 700);
this.vlcControl1.BackColor = System.Drawing.Color.Black;
this.vlcControl1.Name = "vlcControl2";
this.vlcControl1.Spu = -1;
this.vlcControl1.TabIndex = 0;
this.vlcControl1.Text = "vlcControl2";
this.vlcControl1.VlcMediaplayerOptions = null;
vlcControl1.VlcLibDirectory = new System.IO.DirectoryInfo(ConfigurationManager.AppSettings.Get("pathVLC64").ToString());
this.Controls.Add(this.vlcControl1);
((System.ComponentModel.ISupportInitialize)(this.vlcControl1)).EndInit();
}
string uri = ConfigurationManager.AppSettings.Get("urlVideo").ToString();
string[] options = { ":network-caching=1000" };
vlcControl1.Play(new Uri(uri), options);
就是用 vlcControl1.Play(new Uri(uri), options); 的方式打开。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
tableLayoutPanel1.Dock = DockStyle.Fill;
}
bool isVedioOPen = false;
private void button1_Click(object sender, EventArgs e)
{
if (!isVedioOPen)
{
isVedioOPen = true;
button_vedio.Text = "关闭视频";
//vlcControl1.Play(new Uri("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi"));
//vlcControl1.Play(new Uri("rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov"));
string[] options = { ":network-caching=300" };
vlcControl1.Play(new Uri("rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov"), options);
}
else
{
isVedioOPen = false;
button_vedio.Text = "打开视频";
vlcControl1.Stop();
vlcControl1.Refresh();
}
}
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 (AssemblyName.GetAssemblyName(currentAssembly.Location).ProcessorArchitecture == ProcessorArchitecture.X86)
e.VlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, @"lib\x86\"));
else
e.VlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, @"lib\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);
}
}
}
这个事件在这儿。然后在运行路径下,新建lib文件夹,分别支持x86和x64,
":network-caching=300"意思是延迟300毫秒,实际效果比之前延迟两秒好很多,肉眼感觉一秒钟没到,视频就跟着镜头和实物更新了。