如何在Linux上使用LibvlcSharp?

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

我正在尝试在Linux安装上使用LibvlcSharp(Ubuntu 18.04)。我遵循所有的指示,包括这一个Getting started on LibVLCSharp.Gtk for Linux但我的应用程序总是崩溃。它在Windows上完美运行,因为我们可以添加VideoLAN.LibVLC.Windows包,但我找不到类似的Linux。

我的代码:

static void Main(string[] args)
    {
        // Record in a file "record.ts" located in the bin folder next to the app
        var currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
        var destination = Path.Combine(currentDirectory, "record.ts");

        // Load native libvlc library
        Core.Initialize();

        using (var libvlc = new LibVLC())
        //var libvlc = "/usr/lib/x86_64-linux-gnu/";
        using (var mediaPlayer = new MediaPlayer(libvlc))
        {
            // Redirect log output to the console
            libvlc.Log += (sender, e) => Console.WriteLine($"[{e.Level}] {e.Module}:{e.Message}");

            // Create new media with HLS link
            var urlRadio = "http://transamerica.crossradio.com.br:9126/live.mp3";
            var media = new Media(libvlc, urlRadio, FromType.FromLocation);

            // Define stream output options. 
            // In this case stream to a file with the given path and play locally the stream while streaming it.
            media.AddOption(":sout=#file{dst=" + destination + "}");
            media.AddOption(":sout-keep");

            // Start recording
            mediaPlayer.Play(media);

            Console.WriteLine($"Recording in {destination}");
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
    }

错误消息:

未处理的异常:LibVLCSharp.Shared.VLCException:无法在本机端执行instanciation。确保在/ media / RadioRecorderLibVlcSharp /中的RadioRecorderLibVlcSharp.Program.Main(String [] args)的LibVLCSharp.Shared.Internal..ctor(Func1 create, Action1发布)中的平台特定项目中安装了正确的VideoLAN.LibVLC。[YourPlatform]包。 Program.cs:第19行

有人可以帮帮我吗?

谢谢

linux libvlc libvlcsharp
2个回答
0
投票

你能试试apt-get install vlc吗?这似乎有助于获得系统上所有必需的插件/ deps(虽然它可能会从官方的ubuntu代表中获取vlc 2.x)。


0
投票

它在mtz回答后运行,运行apt-get install vlc命令!

但它只有在我评论这条线时才有效:

libvlc.Log += (sender, e) => Console.WriteLine($"[{e.Level}] {e.Module}:{e.Message}");

如果未注释此行,则会发生以下错误:

未处理的异常:System.DllNotFoundException:无法加载共享库'msvcrt'或其依赖项之一。为了帮助诊断加载问题,请考虑设置LD_DEBUG环境变量:libmsvcrt:无法打开共享对象文件:LibVLCSharp上的LibVLCSharp.Shared.Helpers.MarshalUtils.Native._vscprintf(String format,IntPtr ptr)中没有此类文件或目录。 LibVLCSharp.Shared.LibVLC.add_Log上的LibVLCSharp.Shared.LibVLC.Native.LibVLCLogSet(IntPtr libVLC,LogCallback cb,IntPtr数据)中的Shared.LibVLC.OnLogInternal(IntPtr数据,LogLevel级别,IntPtr ctx,String格式,IntPtr args)(位于/home/RadioRecorderLibVlcSharp/Program.cs:line 24中的RadioRecorderLibVlcSharp.Program.Main(String [] args)的EventHandler`1值)

我搜索过这个dll,但我找不到。有人可以帮帮我吗?

谢谢

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