2

I'am playing arround with libVLCSharp and I found a wired behavior. Actually I have no problem creating a media and playing it with MediaPlayer. However when I try to create a Media from MediaList it breaks with the followig message:

Failed to perform instanciation on the native side. Make sure you installed the correct VideoLAN.LibVLC.[YourPlatform] package in your platform specific project

What I wanted to achive is video merging using ":sout=#gather" pipe.

My code is very basic :

Core.Initialize();

using (var libvlc = new LibVLC())
using (var mediaPlayer = new MediaPlayer(libvlc))
{
    Media media1 = new Media(libvlc, @"C:\Temp\SampleVideo.mp4");
    Media media2 = new Media(libvlc, @"C:\Temp\SampleVideo.mp4");
    MediaList list = new MediaList(libvlc);
    list.AddMedia(media1);
    list.AddMedia(media2);

    Media mediaList = new Media(list); <-- Error here

    ...
}

I have 2 nuget packages used in my project:

  • LibVLCSharp v3.0.2 June 12
  • VideoLAN.LibVLC.Windows v3.0.7 June 10
Dmitry
  • 2,033
  • 1
  • 22
  • 31
  • I'm not sure this has ever been tested, as the MediaList feature is something deprecated. Can you report your bug here ? https://code.videolan.org/videolan/LibVLCSharp/issues – cube45 Jun 12 '19 at 13:04
  • Thx. Yes I'am reporting it. Do you know if there is an alternative to MediaList to perform Media merging like with #gather? – Dmitry Jun 12 '19 at 13:58
  • Thanks for reporting it. I'm putting the link here : https://code.videolan.org/videolan/LibVLCSharp/issues/167 – cube45 Jun 12 '19 at 15:05
  • I'm not sure that using a playlist for that will work the way you expect, but I think there is definitely a bug in LibVLCSharp, or at least something we should look into. – cube45 Jun 12 '19 at 15:06
  • @cube45 It still is the same behavior, 7 years after this question was asked. And if it's depcrecated, what's the way to play different videos after each other seemlessly? – John Jun 27 '19 at 11:46
  • @John, this question was asked on June, the 12nd 2019, not in 2012. LibVLCSharp is really recent and actively maintained. – cube45 Jun 27 '19 at 12:55
  • Oh, my bad. Sorry about that. (American date notations sometimes still confuse me.) – John Jun 27 '19 at 12:57
  • Sorry guys I had to stop working on m'y project for a while. However i did test SetMedia ans yes this avoids thé exception but i need some more testing to check whether i got the list transcoded. – Dmitry Jun 27 '19 at 12:59

1 Answers1

1

You want to be using SetMedia for this, not AddMedia.

Associate media instance with this media list instance.

https://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media__list.html#ga96a38e5aabb5781c2f1932d332363eef

Core.Initialize();

using(var libVLC = new LibVLC())
{
    var media1 = new Media(libVLC, "https://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4", FromType.FromLocation);
    var mediaList = new MediaList(libVLC);
    mediaList.SetMedia(media1);
    var media2 = new Media(mediaList);
}
mfkl
  • 1,914
  • 1
  • 11
  • 21
  • 1
    If it can only be one item it's not going to be much of a list. – John Jun 27 '19 at 11:44
  • You can add as many items as you want to the list. _Association_ is something else. – mfkl Jun 28 '19 at 07:19
  • And how? It doesn't work with `AddMedia` as @Dmitry noticed: you get the bespoke exception. And `SetMedia` replaces the one that was set before. – John Jun 28 '19 at 07:29
  • By "it doesn't work", you mean you can't set a mediaList on a MediaPlayer? True, you need a MediaListPlayer for that, which isn't part of the libvlcsharp API (and wont be). – mfkl Jun 29 '19 at 10:57
  • Yes I cam across MediaListPlayer in libvlc docs. Why wont it be implemented in libvlcsharp? – Dmitry Jun 29 '19 at 11:21
  • because I think that API is overkill and you're better off managing your own playlist. Things might change in version 4. – mfkl Jun 29 '19 at 11:54
  • @mfkl Please, is there a way to play a specific item on the list ? I can see play_item_at_index in the python api. but this is not available in C# – Damien Doumer Mar 05 '21 at 12:59
  • Just access the item with [] like you normally would in a dotnet list – mfkl Mar 08 '21 at 02:23