首先感謝 https://stackoverflow.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毫秒,實際效果比之前延遲兩秒好很多,肉眼感覺一秒鍾沒到,視頻就跟着鏡頭和實物更新了。
