使用Vlc.Dotnet for WPF播放流中的视频

时间:2018-10-29 10:21:06

标签: c# wpf libvlc vlc.dotnet

我希望我的WPF应用程序播放给定流中的视频。尝试使用google,但未找到最新Vlc.Dotnet.Wpf版本的有效示例。我已经用NuGet安装了最新的软件包,这是到目前为止的内容:

我的XAML:

    <Vlc:VlcControl xmlns:Vlc="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf" x:Name="vlcPlayer" />

C#代码:

        vlcPlayer.BeginInit();
        vlcPlayer.MediaPlayer.VlcLibDirectory = new DirectoryInfo(@"C:\Program Files (x86)\VideoLAN\VLC\");
        vlcPlayer.EndInit();

        vlcPlayer.MediaPlayer.Play(new Uri("http://79.170.191.118:1935/formula55_2/stream55_2/playlist.m3u8"));

我跑步时什么也没发生。但是,流在Vlc Player中可以正常工作。我在这里有什么选择?

谢谢。

1 个答案:

答案 0 :(得分:1)

这应该使您入门:

public MainWindow()
{
    InitializeComponent();
    var currentAssembly = Assembly.GetEntryAssembly();
    var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
    // Default installation path of VideoLAN.LibVLC.Windows
    var libDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));

    this.VlcControl.SourceProvider.CreatePlayer(libDirectory/* pass your player parameters here */);
    this.VlcControl.SourceProvider.MediaPlayer.Play(new Uri("http://79.170.191.118:1935/formula55_2/stream55_2/playlist.m3u8"));
}

您将需要安装https://www.nuget.org/packages/VideoLAN.LibVLC.Windows/,这是在.NET中使用libvlc库的正确方法。

下一次,请发布一些日志,否则主要是猜测。同时查看官方示例https://github.com/ZeBobo5/Vlc.DotNet/tree/develop/src/Samples