public CFNotificationObserverToken AddObserver(string name, INativeObject objectToObserve, Action <string, NSDictionary?> notificationHandler, CFNotificationSuspensionBehavior suspensionBehavior = CFNotificationSuspensionBehavior.DeliverImmediately) { if (darwinnc is not null && darwinnc.Handle == Handle) { if (name is null) { throw new ArgumentNullException(nameof(name), "When using the Darwin Notification Center, the value passed must not be null"); } } var strHandle = CFString.CreateNative(name); name = name ?? NullNotificationName; var token = new CFNotificationObserverToken(name) { centerHandle = Handle, nameHandle = strHandle, observedObject = objectToObserve.GetHandle(), listener = notificationHandler }; // // To allow callbacks to add observers, we duplicate the list of listeners on AddObserver // We do the duplication on AddObserver, instead of making a copy on the notification // callback, as we expect the notification callback to be a more common operation // than the AddObserver operation // List <CFNotificationObserverToken>?listenersForName; lock (listeners){ if (!listeners.TryGetValue(name, out listenersForName)) { listenersForName = new List <CFNotificationObserverToken> (1); CFNotificationCenterAddObserver(center: Handle, observer: Handle, callback: NotificationCallback, name: strHandle, obj: token.observedObject, suspensionBehavior: (IntPtr)suspensionBehavior); } else { listenersForName = new List <CFNotificationObserverToken> (listenersForName); } listenersForName.Add(token); listeners [name] = listenersForName; } return(token); }
public Error PlayerPrefetch(ITrack track) { AssertHandle(); INativeObject nativeObject = track as INativeObject; if (nativeObject == null) { throw new ArgumentException("Invalid argument"); } lock (Spotify.Mutex) { return(Spotify.sp_session_player_prefetch(Handle, nativeObject.GetHandle())); } }