Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaManager is not stopped and disposed on PopAsync #881

Open
fbcom92 opened this issue Oct 26, 2022 · 1 comment
Open

MediaManager is not stopped and disposed on PopAsync #881

fbcom92 opened this issue Oct 26, 2022 · 1 comment

Comments

@fbcom92
Copy link

fbcom92 commented Oct 26, 2022

馃挰 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 !

@Abuelhija
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants