Search code examples
linuxlibvlclibvlcsharp

How to use LibvlcSharp on Linux?


I'm trying to use LibvlcSharp on a linux installation (Ubuntu 18.04). I'm following all the instructions, including this one Getting started on LibVLCSharp.Gtk for Linux but my application always crash. It's working perfectly on windows, because there we can add VideoLAN.LibVLC.Windows package, but I couldn't find someting similar for Linux.

My code:

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

The error message:

Unhandled Exception: LibVLCSharp.Shared.VLCException: Failed to perform instanciation on the native side. Make sure you installed the correct VideoLAN.LibVLC.[YourPlatform] package in your platform specific project at LibVLCSharp.Shared.Internal..ctor(Func1 create, Action1 release) at RadioRecorderLibVlcSharp.Program.Main(String[] args) in /media/RadioRecorderLibVlcSharp/Program.cs:line 19

Anyone can help me?

thanks


Solution

  • Can you try apt-get install vlc? That seems to help getting all the required plugins/deps on your system (though it will pull vlc 2.x from the official ubuntu rep probably).