I have a simple project (tried it with Shell also), with a MainPage calling a VideoPage with Navigation.PushAsync(new VideoPage()).
On the VideoPage, the media is played correctly. If I press back button (or call the Navigation.PopAsync() manually on a button click...), I can hear the video still playing when the page is removed from stack.
I thought the MediaManager would be stopped and disposed when the page is removed from the stack. So what do I miss ?
on your VideoPage:
protected override void OnDisappearing()
{
base.OnDisappearing();
_viewmodel.StopPlayer();
_viewmodel = null;
}
on your ViewModel (you can also do it on VideoPage)
public async void StopPlayer()
{
try
{
// await Endpoints.FileService.ClearCacheAsync(); if playing from stream then clear cache
IsBusy = false;
if (IsPlaying)
{
CrossMediaManager.Current.Notification.ShowPlayPauseControls = true;
await CrossMediaManager.Current.Pause();
await Task.Delay(50);
await CrossMediaManager.Current.Stop();
CrossMediaManager.Current.Notification.UpdateNotification();
IsPlaying = false;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message)
}
💬 Questions and Help
Hi,
I have a simple project (tried it with Shell also), with a MainPage calling a VideoPage with Navigation.PushAsync(new VideoPage()). On the VideoPage, the media is played correctly. If I press back button (or call the Navigation.PopAsync() manually on a button click...), I can hear the video still playing when the page is removed from stack. I thought the MediaManager would be stopped and disposed when the page is removed from the stack. So what do I miss ?
Thanks !