public void StopNotification()
 {
     if (started)
     {
         started = false;
         controller.UnregisterCallback(mCb);
         try
         {
             notificationManager.Cancel(NotificationId);
             service.UnregisterReceiver(this);
         }
         catch (ArgumentException)
         {
             // ignore if the receiver is not registered.
         }
         service.StopForeground(true);
     }
 }
        public void StopNotification()
        {
            if (!started)
            {
                return;
            }
            started = false;

            controller.UnregisterCallback(callback);
            try
            {
                NotificationManager.Cancel(NotificationId);
                Service.UnregisterReceiver(this);
            }
            catch (IllegalArgumentException ex)
            {
            }
            Service.StopForeground(true);
        }
        void UpdateSessionToken()
        {
            var freshToken = Service.SessionToken;

            if (freshToken == null || sessionToken == freshToken)
            {
                return;
            }

            controller?.UnregisterCallback(callback);

            sessionToken      = freshToken;
            controller        = new MediaControllerCompat(Service, sessionToken);
            transportControls = controller.GetTransportControls();

            if (started)
            {
                controller.RegisterCallback(callback);
            }
        }
        void UpdateSessionToken()
        {
            var freshToken = service.SessionToken;

            if (sessionToken == null && freshToken != null ||
                sessionToken != null && sessionToken != freshToken)
            {
                controller?.UnregisterCallback(mCb);

                sessionToken = freshToken;
                if (sessionToken != null)
                {
                    controller        = new MediaControllerCompat(service, sessionToken);
                    transportControls = controller.GetTransportControls();
                    if (started)
                    {
                        controller.RegisterCallback(mCb);
                    }
                }
            }
        }