-1

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?

2

1 Answer 1

-1

The problem was, that i had to reattach a new VideoView to the main layout like described here:
https://code.videolan.org/mfkl/libvlcsharp-samples/-/tree/master/ForegroundBackground?ref_type=heads
Although i think in MAUI its not possible to reattach a VideoView just like that, but i got it running with connecting the Maui Viewhandler with the Android.Widget.FrameLayout, a class that contains the VideoView. So I could replace the VideoView inside the FrameLayout without rewiring the Handlers.
(At least thats what i think is happening there).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.