public DelayedStopHandler(MusicService service) { weakReference = new WeakReference <MusicService>(service); }
public MediaNotificationManager(MusicService serv) { service = serv; UpdateSessionToken(); notificationColor = ResourceHelper.GetThemeColor(service, Android.Resource.Attribute.ColorPrimary, Color.DarkGray); notificationManager = NotificationManagerCompat.From(service); string pkg = service.PackageName; pauseIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPause).SetPackage(pkg), PendingIntentFlags.CancelCurrent); playIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPlay).SetPackage(pkg), PendingIntentFlags.CancelCurrent); previousIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPrev).SetPackage(pkg), PendingIntentFlags.CancelCurrent); nextIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionNext).SetPackage(pkg), PendingIntentFlags.CancelCurrent); notificationManager.CancelAll(); mCb.OnPlaybackStateChangedImpl = (state) => { playbackState = state; LogHelper.Debug(Tag, "Received new playback state", state); if (state.State == PlaybackStateCompat.StateStopped || state.State == PlaybackStateCompat.StateNone) { StopNotification(); } else { Notification notification = CreateNotification(); if (notification != null) { notificationManager.Notify(NotificationId, notification); } } }; mCb.OnMetadataChangedImpl = (meta) => { metadata = meta; LogHelper.Debug(Tag, "Received new metadata ", metadata); Notification notification = CreateNotification(); if (notification != null) { notificationManager.Notify(NotificationId, notification); } }; mCb.OnSessionDestroyedImpl = () => { LogHelper.Debug(Tag, "Session was destroyed, resetting to the new session token"); try { UpdateSessionToken(); } catch (Exception e) { LogHelper.Error(Tag, e, "could not connect media controller"); } }; }