简体   繁体   English

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

[英]Play video from stream using Vlc.Dotnet for WPF

I want my WPF application to play video from a given stream. 我希望WPF应用程序播放给定流中的视频。 Tried to google, but didn't find any working example with the latest Vlc.Dotnet.Wpf version. 尝试使用google,但找不到最新的Vlc.Dotnet.Wpf版本的任何有效示例。 I have installed the latest package with NuGet and here is what I have so far: 我已经用NuGet安装了最新的软件包,这是到目前为止的内容:

My XAML: 我的XAML:

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

C# code: 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"));

When I run, nothing happens. 当我跑步时,什么也没发生。 However stream works fine in Vlc Player. 但是,流在Vlc Player中可以正常工作。 What are my options here? 我在这里有什么选择?

Thanks in advance. 提前致谢。

This should get you started: 这应该使您开始:

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"));
}

You will need to install https://www.nuget.org/packages/VideoLAN.LibVLC.Windows/ which is the correct way to consume libvlc libraries in .NET. 您将需要安装https://www.nuget.org/packages/VideoLAN.LibVLC.Windows/ ,这是在.NET中使用libvlc库的正确方法。

For next time, post some logs please as otherwise it's mostly guesswork. 对于下一次,请发布一些日志,否则主要是猜测。 Also check out the official samples https://github.com/ZeBobo5/Vlc.DotNet/tree/develop/src/Samples 另请查看官方样本https://github.com/ZeBobo5/Vlc.DotNet/tree/develop/src/Samples

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM