How to dispose CrossMediaManager properly?
I'm playing an HLS content on CrossMediaManager. When users press back, I'm trying to dispose the player, but the player is still playing, I can see it's running on notification drawer and I can listen to video. Here is the code I've tried.
VideoPlayer is the Reference name of the VideoView
protected override void OnDisappearing()
{
base.OnDisappearing();
CrossMediaManager.Current.Dispose();
VideoPlayer.Dispose();
}
Hi!
I have the same problem ... Currently, I am trying:
async protected override void OnDisappearing()
{
await CrossMediaManager.Current.Stop();
video.Dispose();
CrossMediaManager.Current.Dispose();
}
With no luck. I wonder if there is any flag I could put on "False" that would make the whole notification drawer dissapear, also. I do not want the user to "control" the media being played from the notification drawer.
Any hint / help is appreciated!
Thanks!
Hello, same boat here
I tried so many things to dispose the video player properly. The behaviour I am trying to achieve is a button that stops the video and removes all its associated notifications.
CrossMediaManager.Current.Dispose(); Doesn't seem to interact with the notification drawer.
I tried
CrossMediaManager.Current.Notification = null;
var manager = CrossMediaManager.Current.Notification as MediaManager.Platforms.Android.Notifications.NotificationManager;
var playerNotificationManager = manager.PlayerNotificationManager;
playerNotificationManager.SetNotificationListener(null);
playerNotificationManager.SetPlayer(null);
playerNotificationManager.SetMediaSessionToken(null);
playerNotificationManager = null;
Also tried setting the Media session to inactive, cancelling all intents from the Application.Context but nothing seems to work.
I think that CrossMediaManager.Current.Dispose(); is supposed to close the notification from what I read in the source code but nothing really happens.
Seems like a bug to me? Or maybe an oversight?
Would greatly appreciate some help. Thank you
I've also tried to use a custom notification manager by replacing :
CrossMediaManager.Current.Notification = new MyCustomManager(); but it didn't seem to have the functionalities I am looking for to shut the notification.
I've also tried stop the play, disable notification and dispose the instance. None of them worked, at the end i found a old YouTube video says the version 0.9.7 has problems so using the version 0.9.0, that helped me, version 0.9.0 works fine you can close notification just with stop command.
Hello!
I have just tried downgrading the version and it seems that every version below 1.0.7 does not work properly within my project. Downgrading sounds like a sweet workaround but I would be scared that it creates bugs that have already been fixed.
this worked for me:
public async void StopPlayer() { try { //await Endpoints.FileService.ClearCacheAsync(); if played 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); }
}