XamarinMediaManager icon indicating copy to clipboard operation
XamarinMediaManager copied to clipboard

MediaManager is not stopped and disposed on PopAsync

Open fbcom92 opened this issue 2 years ago • 1 comments

💬 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 !

fbcom92 avatar Oct 26 '22 08:10 fbcom92

  1. on your VideoPage: protected override void OnDisappearing() { base.OnDisappearing(); _viewmodel.StopPlayer(); _viewmodel = null; }

    2. 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)
         }
    

Abuelhija avatar Sep 06 '23 12:09 Abuelhija