MediaElement with NavigationPage
Lifecycle events don't appear to be working on the MediaElement if the page is part of a NavigationPage.
Minimal project and steps to reproduce
The easiest way to reproduce is to take the MediaElement sample project and in the App constructor replace
- Clone https://code.videolan.org/mfkl/libvlcsharp-samples.git
- Open libvlcsharp-samples-windows in VS 2019 16.5.2
- Update Nuget packages. At the time I tested, Xamarin.Forms (and related packages) was v126.96.36.1990. LibVLCSharp.Forms v3.4.3, NETStandard.Library v2.0.3. On Android VideoLan.libVLC.Android v3.2.0
- Run MediaElement.Android. I built against Android 9.0, tested on an x86 hyper-v Pixel 2 Pie 9.0 API 28 with Google Play.
- Swap to background, switch apps, come back. The player pauses (console/debug messages stop, position is saved). Resumes playback continues where it left off (you can briefly see the controls jump to the prior playback position).
- Stop App
- Change Line 15 of MediaElement/App.xaml.cs from MainPage = new MainPage(); to MainPage = new NavigationPage(new MainPage());
- Repeat steps 4, 5. App does not stop printing console messages when backgrounded. Does not resume.
What is the current bug behavior?
VLC debug messages continue to print out while backgrounded. Switching back to the app starts the video over again.
What is the expected correct behavior?
VLC debug messages stop (playback stops). Switching back to the app starts playback again from the previous position.
Does it work on other plaforms? Does it work with the official VLC apps?
It works when not using navigation pages and with the provided sample app. I'm re-installing my mac but can test again later.
Relevant logs and/or screenshots
- OS: Android
- Version 9.0/API28
- Device: Pixel 2 Hyper-V x86 emulator
- LibVLC version and architecture VideoLan.libVLC.Android v3.2.0
- LibVLCSharp version LibVLCSharp.Forms 3.4.3
Perhaps the PageAppearing/PageDisappearing, (e == this.FindAncestor()) call, eg Line 202. In some tinkering I did I think it's also possible PageDisappearing is being called when it backgrounds which then unsubscribes from onresume.