Ejemplo n.º 1
0
        internal static IPlaylist Get(ISession session, IntPtr handle)
        {
            lock (_instanceLock)
            {
                NativePlaylist instance;

                if (!_instances.TryGetValue(handle, out instance))
                {
                    instance = new NativePlaylist(session, handle);
                    _instances.Add(handle, instance);
                    instance.Initialize();
                }

                return instance;
            }
        }
Ejemplo n.º 2
0
        public NativePlaylistCallbacks(NativePlaylist playlist, bool registerCallbacks = true)
        {
            _registerCallbacks = registerCallbacks;
            _playlist = playlist;

            if (registerCallbacks)
            {
                _tracksAdded = OnTracksAddedCallback;
                _tracksRemoved = OnTracksRemovedCallback;
                _tracksMoved = OnTracksMovedCallback;
                _playlistRenamed = OnRenamedCallback;
                _playlistStateChanged = OnStateChangedCallback;
                _playlistUpdateInProgress = OnUpdateInProgressCallback;
                _playlistMetadataUpdated = OnMetadataUpdatedCallback;
                _trackCreatedChanged = OnTrackCreatedChangedCallback;
                _trackSeenChanged = OnTrackSeenChangedCallback;
                _descriptionChanged = OnDescriptionChangedCallback;
                _imageChanged = OnImageChangedCallback;
                _subscribersChanged = OnSubscribersChangedCallback;

                _callbacks = new Spotify.PlaylistCallbacks
                {
                    tracks_added = Marshal.GetFunctionPointerForDelegate(_tracksAdded),
                    tracks_removed = Marshal.GetFunctionPointerForDelegate(_tracksRemoved),
                    tracks_moved = Marshal.GetFunctionPointerForDelegate(_tracksMoved),
                    playlist_renamed = Marshal.GetFunctionPointerForDelegate(_playlistRenamed),
                    playlist_state_changed = Marshal.GetFunctionPointerForDelegate(_playlistStateChanged),
                    playlist_update_in_progress = Marshal.GetFunctionPointerForDelegate(_playlistUpdateInProgress),
                    playlist_metadata_updated = Marshal.GetFunctionPointerForDelegate(_playlistMetadataUpdated),
                    track_created_changed = Marshal.GetFunctionPointerForDelegate(_trackCreatedChanged),
                    track_seen_changed = Marshal.GetFunctionPointerForDelegate(_trackSeenChanged),
                    description_changed = Marshal.GetFunctionPointerForDelegate(_descriptionChanged),
                    image_changed = Marshal.GetFunctionPointerForDelegate(_imageChanged),
                    subscribers_changed = Marshal.GetFunctionPointerForDelegate(_subscribersChanged)
                };

                lock (Spotify.Mutex)
                {
                    Spotify.sp_playlist_add_callbacks(_playlist.Handle, ref _callbacks, IntPtr.Zero);
                }
            }
        }
        public NativePlaylistCallbacks(NativePlaylist playlist, bool registerCallbacks = true)
        {
            _registerCallbacks = registerCallbacks;
            _playlist          = playlist;

            if (registerCallbacks)
            {
                _tracksAdded              = OnTracksAddedCallback;
                _tracksRemoved            = OnTracksRemovedCallback;
                _tracksMoved              = OnTracksMovedCallback;
                _playlistRenamed          = OnRenamedCallback;
                _playlistStateChanged     = OnStateChangedCallback;
                _playlistUpdateInProgress = OnUpdateInProgressCallback;
                _playlistMetadataUpdated  = OnMetadataUpdatedCallback;
                _trackCreatedChanged      = OnTrackCreatedChangedCallback;
                _trackSeenChanged         = OnTrackSeenChangedCallback;
                _descriptionChanged       = OnDescriptionChangedCallback;
                _imageChanged             = OnImageChangedCallback;
                _subscribersChanged       = OnSubscribersChangedCallback;

                _callbacks = new Spotify.PlaylistCallbacks
                {
                    tracks_added                = Marshal.GetFunctionPointerForDelegate(_tracksAdded),
                    tracks_removed              = Marshal.GetFunctionPointerForDelegate(_tracksRemoved),
                    tracks_moved                = Marshal.GetFunctionPointerForDelegate(_tracksMoved),
                    playlist_renamed            = Marshal.GetFunctionPointerForDelegate(_playlistRenamed),
                    playlist_state_changed      = Marshal.GetFunctionPointerForDelegate(_playlistStateChanged),
                    playlist_update_in_progress = Marshal.GetFunctionPointerForDelegate(_playlistUpdateInProgress),
                    playlist_metadata_updated   = Marshal.GetFunctionPointerForDelegate(_playlistMetadataUpdated),
                    track_created_changed       = Marshal.GetFunctionPointerForDelegate(_trackCreatedChanged),
                    track_seen_changed          = Marshal.GetFunctionPointerForDelegate(_trackSeenChanged),
                    description_changed         = Marshal.GetFunctionPointerForDelegate(_descriptionChanged),
                    image_changed               = Marshal.GetFunctionPointerForDelegate(_imageChanged),
                    subscribers_changed         = Marshal.GetFunctionPointerForDelegate(_subscribersChanged)
                };

                lock (Spotify.Mutex)
                {
                    Spotify.sp_playlist_add_callbacks(_playlist.Handle, ref _callbacks, IntPtr.Zero);
                }
            }
        }