can anybody help me with a c# xamarin code sample how to include into a layout as a VideoView control a LibVLC VideoView? I want to display a short video and then, after it's finished to return on my main layout. I succeeded to include the VLC player in my project (thanks to http://xamaringuyshow.com/2019/08/23/xamarin-forms-vlc-video-payer/ ), but I want to play the video in a separate layout and return after the clip is finished.
When the clip is done (but the media player doesn't have any control buttons - to seek the video, to pause or to play - another problem...) , and I try to continue with the main thread of my application, I get a "Only the original thread that created a view hierarchy can touch its views" error and the application is crashed.
This is the part of my code with the LibVLC:
public void ReplayVideoVLC(string link)
{
mainActivity.SetContentView(App3.Resource.Layout.VideoFullScreen);
_libVLC = new LibVLC();
_mediaPlayer = new MediaPlayer(_libVLC)
{
EnableHardwareDecoding = true
};
_videoView = new LibVLCSharp.Platforms.Android.VideoView(mainActivity) { MediaPlayer = _mediaPlayer };
mainActivity.AddContentView(_videoView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent));
var media = new Media(_libVLC, link, FromType.FromLocation);
Core.Initialize();
_videoView.SetZOrderOnTop(true);
_videoView.MediaPlayer.Stopped += MediaPlayer_Stopped;
_videoView.MediaPlayer.EncounteredError += MediaPlayer_EncounteredError;
video_error = false;
vlc_video_playing = true;
try
{
_videoView.MediaPlayer.Play(media);
}
catch (Exception exx)
{
exx = exx;
vlc_video_playing = false;
}
}
private void MediaPlayer_EncounteredError(object sender, EventArgs e)
{
//error on VLC replay...
video_error = true;
Xamarin.Forms.Device.OpenUri(new Uri(client.current_video_url));
vlc_video_playing = false;
}
private void MediaPlayer_Stopped(object sender, EventArgs e)
{
try
{
_videoView.MediaPlayer = null;
_videoView = null;
}
catch (Exception exx)
{
//exx = exx;
}
if (!video_error)
{
mainActivity.ContinueGame();
}
else
{
Xamarin.Forms.Device.OpenUri(new Uri(client.current_video_url));
}
vlc_video_playing = false;
}
```c#