I am trying to receive multiple RTSP streams using Libvlcsharp.
I need to display multiple streams at once, so i declared a VideoView List,
private List<VideoView> videoList = new List<VideoView>();
and declared function that creates a VideoView and adds it to the list and flowlayoutpanel.
private async Task AddPlayerAsync()
{
await Task.Run(async () =>
{
var player = new MediaPlayer(libVLC);
var Media = new Media(libVLC, new Uri(textBox1.Text));
var video = new VideoView();
video.Size = new Size(200, 200);
video.MediaPlayer = player;
((System.ComponentModel.ISupportInitialize)video).EndInit();
var uiUpdatedTask = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
panel1.BeginInvoke((MethodInvoker)delegate
{
panel1.Controls.Add(video);
uiUpdatedTask.SetResult(true);
});
await uiUpdatedTask.Task.ConfigureAwait(false);
lock (videoList)
{
// Add to a list
videoList.Add(video);
}
player.Play(Media);
});
}
And i saw the crossthread exeption in: panel1.Controls.Add(video);
Is there an error in the videoview creation step?
I tried using begininit() and endinit(), but the result was the same.
I also tried set video.MediaPlayer = player;
after panel1.Controls.Add(video);
.