So I am using the libVLC Package for my .Net MAUI App to Stream some Media on an Android tablet. As a guideline i was using the libVLC Maui Sample from here: https://code.videolan.org/videolan/LibVLCSharp/-/tree/3.x/samples
It works just fine, but sadly I am not able to come up with a solution to get the Media running as it should, after minimizing the App and getting it back to the foreground. Idk why, but it seems like the player is not designed to resume after the surface is destroyed. Thats why i tried disposing the Mediaplayer and VLC Objects within the Lifecycle Method OnSleep and reconstruct them on OnResume.
MainViewModel.cs:
public void OnSleep()
{
MediaPlayer.Dispose();
LibVLC.Dispose();
}
public void OnResume()
{
LibVLC = new LibVLC(enableDebugLogs: true);
using var media = new Media(LibVLC, new Uri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"));
MediaPlayer = new Shared.MediaPlayer(LibVLC)
{
Media = media
};
MediaPlayer.Play();
}
With App.xaml.cs:
protected override void OnSleep()
{
base.OnSleep();
Page page = Shell.Current.CurrentPage;
if (page.GetType().Equals(typeof(MainPage)))
{
var mainpage = (MainPage)Shell.Current.CurrentPage;
var mainvm = (MainViewModel)mainpage.BindingContext;
mainvm.OnSleep();
}
}
protected override void OnResume()
{
base.OnResume();
Page page = Shell.Current.CurrentPage;
if (page.GetType().Equals(typeof(MainPage)))
{
var mainpage = (MainPage)Shell.Current.CurrentPage;
var mainvm = (MainViewModel)mainpage.BindingContext;
mainvm.OnResume();
}
}
It works as intended, but the size of the mediaplayer is suddenly changed from there on like this:
enter image description here
Changing the size or position of the Mediaplayer with .AspectRatio or .Scale is not possible any more.
Is there a way to keep the Mediaplayer running in the back ground, or a way to display the Mediaplayer with the initial position and size, after the surface is destroyed and built up again?