一、初识VLC
官方网址:https://www.videolan.org/
VLC 是一款自由、开源的跨平台多媒体播放器及框架,可播放大多数多媒体文件,以及 DVD、音频 CD、VCD 及各类流媒体协议。
VLC Media Player(VLC多媒体播放器),最初命名为VideoLAN客户端,是VideoLAN品牌产品,是VideoLAN计划的多媒体播放器。它支持众多音频与视频解码器及文件格式,并支持DVD影音光盘,VCD影音光盘及各类流式协议。它也能作为unicast或multicast的流式服务器在IPv4或IPv6的高速网络连接下使用。它融合了FFmpeg计划的解码器与libdvdcss程序库使其有播放多媒体文件及加密DVD影碟的功能。
二、开发环境搭建
2.1 VS2019 创建新工程
2.2 Nuget安装相关包
2.3 下载VLC最新软件
官网:https://www.videolan.org/
安装:
三、代码
3.1 xaml界面
增加以下引用:
xmlns:vlc="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf"
代码加入以下一行:
<vlc:VlcControl Name="VlcPlayer"/>
完整:
<Window x:Class="VideoPLayer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VideoPLayer"
xmlns:vlc="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<vlc:VlcControl Name="VlcPlayer"/>
</Grid>
</Window>
3.2 后代代码
string currentDirectory = @"C:\Program Files\VideoLAN\VLC";
var vlcLibDirectory = new DirectoryInfo(currentDirectory);
var options = new string[]
{
//添加日志
"--file-logging", "-vvv", "--logfile=Logs.log"
// VLC options can be given here. Please refer to the VLC command line documentation.
};
//初始化播放器
this.VlcPlayer.SourceProvider.CreatePlayer(vlcLibDirectory, options);
//设置播放源
this.VlcPlayer.SourceProvider.MediaPlayer.Play(new Uri(@"D:\program\program\VideoPlayer\video-player\VideoPLayer\VideoPLayer\bin\Debug\01.mp4"));//本地文件。
四、运行
运行前去掉 首选32位 因为下的是64位VLC