Beispiel #1
0
        private void initCallbacks()
        {
            if (this.Pointer == IntPtr.Zero)
                throw new InvalidOperationException("Invalid playlist pointer.");

            this.fn_tracks_added = new tracks_added_delegate(tracks_added);
            this.fn_tracks_removed = new tracks_removed_delegate(tracks_removed);
            this.fn_tracks_moved = new tracks_moved_delegate(tracks_moved);
            this.fn_playlist_renamed = new playlist_renamed_delegate(playlist_renamed);
            this.fn_playlist_state_changed = new playlist_state_changed_delegate(state_changed);
            this.fn_playlist_update_in_progress = new playlist_update_in_progress_delegate(playlist_update_in_progress);
            this.fn_playlist_metadata_updated = new playlist_metadata_updated_delegate(metadata_updated);
            this.fn_track_created_changed = new track_created_changed_delegate(track_created_changed);
            this.fn_track_seen_changed = new track_seen_changed_delegate(track_seen_changed);
            this.fn_description_changed = new description_changed_delegate(description_changed);
            this.fn_image_changed = new image_changed_delegate(image_changed);
            this.fn_track_message_changed = new track_message_changed_delegate(track_message_changed);
            this.fn_subscribers_changed = new subscribers_changed_delegate(subscribers_changed);

            libspotify.sp_playlist_callbacks callbacks = new libspotify.sp_playlist_callbacks();

            callbacks.tracks_added = Marshal.GetFunctionPointerForDelegate(fn_tracks_added);
            callbacks.tracks_removed = Marshal.GetFunctionPointerForDelegate(fn_tracks_removed);
            callbacks.tracks_moved = Marshal.GetFunctionPointerForDelegate(fn_tracks_moved);
            callbacks.playlist_renamed = Marshal.GetFunctionPointerForDelegate(fn_playlist_renamed);
            callbacks.playlist_state_changed = Marshal.GetFunctionPointerForDelegate(fn_playlist_state_changed);
            callbacks.playlist_update_in_progress = Marshal.GetFunctionPointerForDelegate(fn_playlist_update_in_progress);
            callbacks.playlist_metadata_updated = Marshal.GetFunctionPointerForDelegate(fn_playlist_metadata_updated);
            callbacks.track_created_changed = Marshal.GetFunctionPointerForDelegate(fn_track_created_changed);
            callbacks.track_seen_changed = Marshal.GetFunctionPointerForDelegate(fn_track_seen_changed);
            callbacks.description_changed = Marshal.GetFunctionPointerForDelegate(fn_description_changed);
            callbacks.image_changed = Marshal.GetFunctionPointerForDelegate(fn_image_changed);
            callbacks.track_message_changed = Marshal.GetFunctionPointerForDelegate(fn_track_message_changed);
            callbacks.subscribers_changed = Marshal.GetFunctionPointerForDelegate(fn_subscribers_changed);

            _callbacksPtr = Marshal.AllocHGlobal(Marshal.SizeOf(callbacks));
            Marshal.StructureToPtr(callbacks, _callbacksPtr, true);

            libspotify.sp_playlist_add_callbacks(this.Pointer, _callbacksPtr, IntPtr.Zero);
        }
Beispiel #2
0
        private void AddCallbacks()
        {
            _tracksAddedDelegate = TracksAdded;
            _tracksRemovedDelegate = TracksRemoved;
            _tracksMovedDelegate = TracksMoved;
            _playlistRenamedDelegate = PlaylistRenamed;
            _playlistStateChangedDelegate = StateChanged;
            _playlistUpdateInProgressDelegate = PlaylistUpdateInProgress;
            _playlistMetadataUpdatedDelegate = MetadataUpdated;
            _trackCreatedChangedDelegate = TrackCreatedChanged;
            _trackSeenChangedDelegate = TrackSeenChanged;
            _descriptionChangedDelegate = DescriptionChanged;
            _imageChangedDelegate = ImageChanged;
            _trackMessageChangedDelegate = TrackMessageChanged;
            _subscribersChangedDelegate = SubscribersChanged;

            var callbacks = new libspotify.sp_playlist_callbacks
            {
                tracks_added = Marshal.GetFunctionPointerForDelegate(_tracksAddedDelegate),
                tracks_removed = Marshal.GetFunctionPointerForDelegate(_tracksRemovedDelegate),
                tracks_moved = Marshal.GetFunctionPointerForDelegate(_tracksMovedDelegate),
                playlist_renamed = Marshal.GetFunctionPointerForDelegate(_playlistRenamedDelegate),
                playlist_state_changed = Marshal.GetFunctionPointerForDelegate(_playlistStateChangedDelegate),
                playlist_update_in_progress = Marshal.GetFunctionPointerForDelegate(_playlistUpdateInProgressDelegate),
                playlist_metadata_updated = Marshal.GetFunctionPointerForDelegate(_playlistMetadataUpdatedDelegate),
                track_created_changed = Marshal.GetFunctionPointerForDelegate(_trackCreatedChangedDelegate),
                track_seen_changed = Marshal.GetFunctionPointerForDelegate(_trackSeenChangedDelegate),
                description_changed = Marshal.GetFunctionPointerForDelegate(_descriptionChangedDelegate),
                image_changed = Marshal.GetFunctionPointerForDelegate(_imageChangedDelegate),
                track_message_changed = Marshal.GetFunctionPointerForDelegate(_trackMessageChangedDelegate),
                subscribers_changed = Marshal.GetFunctionPointerForDelegate(_subscribersChangedDelegate)
            };

            _callbacksPtr = Marshal.AllocHGlobal(Marshal.SizeOf((object) callbacks));
            Marshal.StructureToPtr(callbacks, _callbacksPtr, true);

            libspotify.sp_playlist_add_callbacks(PlaylistPtr, _callbacksPtr, IntPtr.Zero);
        }