Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# LibVLCSharp player direct feed media

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

These are the packages:

  • https://www.nuget.org/packages/LibVLCSharp.WinForms
  • https://www.nuget.org/packages/VideoLAN.LibVLC.Windows

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#?

like image 751
Daniel Avatar asked Sep 11 '25 22:09

Daniel


2 Answers

Use this Media constructor

new Media(libVLC, new StreamMediaInput(stream));

stream can by any .NET Stream.

This sample is with a torrent stream for example: https://github.com/mfkl/lvst/blob/master/LVST/Program.cs

like image 125
mfkl Avatar answered Sep 14 '25 12:09

mfkl


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();
like image 36
cube45 Avatar answered Sep 14 '25 11:09

cube45