1、通过NuGet安装LibVLCSharp和LibVLCSharp.WPF包。
2、view中引入LibVLCSharp.WPF
cs
xmlns:vlc="clr-namespace:LibVLCSharp.WPF;assembly=LibVLCSharp.WPF"
添加vlc控件:
cs
<vlc:VideoView x:Name="view1"/>
3、后端代码:
cs
private LibVLC _libVLC;
private LibVLCSharp.Shared.MediaPlayer _mediaPlayer;
public MainWindow()
{
InitializeComponent();
Core.Initialize();
_libVLC = new LibVLC();
_mediaPlayer = new LibVLCSharp.Shared.MediaPlayer(_libVLC);
view1.MediaPlayer = _mediaPlayer;
// 替换为你的本地MP4文件路径
var mediaPath = @"C:\Users\000\Desktop\新建文件夹 (2)\1.mp4";
var media = new Media(_libVLC, new Uri(mediaPath));
_mediaPlayer.Play(media);
}
protected override void OnClosed(EventArgs e)
{
_mediaPlayer.Dispose();
_libVLC.Dispose();
base.OnClosed(e);
}
换上自己的文件路径就可以播放了