3

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

Daniel
  • 2,318
  • 2
  • 22
  • 53

2 Answers2

6

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

mfkl
  • 1,914
  • 1
  • 11
  • 21
3

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();
Sorry IwontTell
  • 466
  • 10
  • 29
cube45
  • 3,429
  • 2
  • 24
  • 35
  • Wow, this could be pretty new, I've even had to update the nuget packages to be able to have the MediaInput class available. Thanks – Daniel Apr 09 '20 at 19:06
  • Yes it is new, I added this because I wanted to add more scenarios than just a plain Stream. Enjoy! – cube45 Apr 10 '20 at 05:49