using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using Vlc.DotNet.Forms; namespace RFIDManagement { public partial class FrmVlcPlayer : Form { public SynchronizationContext SyncContext; public VlcControl VlcPlayer; public FrmVlcPlayer() { InitializeComponent(); SyncContext = SynchronizationContext.Current; var currentAssembly = Assembly.GetEntryAssembly(); var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName; var libDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64")); VlcPlayer = new VlcControl(); VlcPlayer.BeginInit(); VlcPlayer.VlcLibDirectory = libDirectory; VlcPlayer.Dock = DockStyle.Fill; VlcPlayer.EndInit(); VlcPlayer.EndReached += OnVlcPlayerEndReached; this.Controls.Add(VlcPlayer); this.FormClosed += OnFrmVlcPlayerFormClosed; } public void PlayVideo(string url) { VlcPlayer.SetMedia(new Uri(url)); VlcPlayer.Play(); } public void CloseWindow(object state) { this.Close(); } /// /// 播放完成后 /// /// /// private void OnVlcPlayerEndReached(object sender, Vlc.DotNet.Core.VlcMediaPlayerEndReachedEventArgs e) { SyncContext.Post(CloseWindow, null); } /// /// 程序关闭后 /// /// /// private void OnFrmVlcPlayerFormClosed(object sender, FormClosedEventArgs e) { VlcPlayer?.Stop(); VlcPlayer?.Dispose(); } } }