Xamarin.Forms: LibVLCSharp lag increases over time

This forum is about all development around libVLC.
ffrige
New Cone
New Cone
Posts: 1
Joined: 28 Oct 2020 03:49

Xamarin.Forms: LibVLCSharp lag increases over time

Postby ffrige » 28 Oct 2020 03:55

I already posted this question in the Xamarin forum but no one has answered so far. I thought this forum might be more helpful...

I am using the LibVLCSharp library in Xamarin.Forms to stream a jpg video from an IP camera. It all works fine, excepts that when I start the application the actual view of the stream lags about 1 second from real-time and then the difference slowly increases until it is in the order of minutes, i.e. I am watching the past.

It makes me think that the stream is being buffered and then displayed. Is there an option to avoid the buffering, just dropping unused frames and keep in synch with reality?

My current code is as follows. The view:

Code: Select all

<shared:VideoView MediaPlayer="{Binding MediaPlayer}" MediaPlayerChanged="VideoView_MediaPlayerChanged" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
The code behind:

Code: Select all

private void VideoView_MediaPlayerChanged(object sender, MediaPlayerChangedEventArgs e) { ((ParametersModel)BindingContext).OnVideoViewInitialized(); }
The model:

Code: Select all

private bool IsLoaded { get; set; } private bool IsVideoViewInitialized { get; set; } private LibVLC LibVLC { get; set; } private MediaPlayer _mediaPlayer; public MediaPlayer MediaPlayer { get => _mediaPlayer; set { _mediaPlayer = value; OnPropertyChanged(); } } private void Initialize() { Core.Initialize(); LibVLC = new LibVLC(); var media = new Media(LibVLC, new Uri("http://192.168.4.1/")); MediaPlayer = new MediaPlayer(LibVLC) { Media = media }; media.Dispose(); } public void OnAppearing() { IsLoaded = true; Play(); } internal void OnDisappearing() { MediaPlayer.Dispose(); LibVLC.Dispose(); } public void OnVideoViewInitialized() { BT_Status = "Now initialized..."; IsVideoViewInitialized = true; Play(); } private void Play() { if (IsLoaded && IsVideoViewInitialized) { BT_Status = "Now playing..."; try { MediaPlayer.Play(); } catch (Exception ex) { BT_Status = ex.ToString(); } } }

mfkl
Developer
Developer
Posts: 739
Joined: 13 Jun 2017 10:41

Re: Xamarin.Forms: LibVLCSharp lag increases over time

Postby mfkl » 28 Oct 2020 04:51

Hi,

Which platform? Which lib version? Can you reproduce with the official VLC app?
https://mfkl.github.io


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 30 guests