Search code examples
c#vlclibvlclibvlcsharp

C# LibVLCSharp player direct feed media


There is a C# application which uses LibVLC via NuGet packages.

These are the packages:

With these packages it is very easy to drop some mediaplayers into your WinForms application.

All you have to do is to initialize a player and give a new Media to it:

LibVLCSharp.Shared.LibVLC libVLC = new LibVLC();

LibVLCSharp.WinForms.VideoView videoView;
videoView.MediaPlayer = new LibVLCSharp.Shared.MediaPlayer(libVLC)

videoView.MediaPlayer.Play(new Media(libVLC, "URL", FromType.FromLocation));

Now I want to feed the mediaplayer with my custom data from a buffer. It can be byte-array, or anything similar. (data shall be considered to come from a valid mp4 file chunk-by-chunk).

How can I achieve that with libVLC in C#?


Solution

  • If you don't want to create a Stream where not needed, you could also implement your own MediaInput class, and implement the required methods

    https://code.videolan.org/videolan/LibVLCSharp/-/blob/master/src/LibVLCSharp/MediaInput.cs

    Then, the usage is the same as @mfkl pointed out. Be careful though, the MediaInput must be disposed!

    this._mediaInput = new MyMediaInput();
    
    mediaPlayer.Play(new Media(libVLC, this._mediaInput));
    
    // At the end
    this._mediaInput.Dispose();