Baseflow / XamarinMediaManager

Cross platform Xamarin plugin to play and control Audio and Video
https://baseflow.com
MIT License
769 stars 306 forks source link

MediaManager is not stopped and disposed on PopAsync #881

Open fbcom92 opened 2 years ago

fbcom92 commented 2 years ago

💬 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 commented 1 year ago
  1. on your VideoPage: protected override void OnDisappearing() { base.OnDisappearing(); _viewmodel.StopPlayer(); _viewmodel = null; }

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