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

问题描述 投票:0回答:1

我希望我的WPF应用程序播放来自给定流的视频。尝试谷歌,但没有找到任何最新的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中运行良好。我有什么选择?

提前致谢。

c# wpf libvlc vlc.dotnet
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.