public NativeSessionCallbacks(NativeSession session)
        {
            _session = session;

            _connectionError = ConnectionErrorCallback;
            _endOfTrack = EndOfTrackCallback;
            _getAudioBufferStats = GetAudioBufferStatsCallback;
            _loggedIn = LoggedInCallback;
            _loggedOut = LoggedOutCallback;
            _logMessage = LogMessageCallback;
            _messageToUser = MessageToUserCallback;
            _metadataUpdated = MetadataUpdatedCallback;
            _musicDelivery = MusicDeliveryCallback;
            _notifyMainThread = NotifyMainThreadCallback;
            _playTokenLost = PlayTokenLostCallback;
            _startPlayback = StartPlaybackCallback;
            _stopPlayback = StopPlaybackCallback;
            _streamingError = StreamingErrorCallback;
            _userinfoUpdated = UserinfoUpdatedCallback;
            _offlineStatusUpdated = OfflineStatusUpdatedCallback;
            _offlineError = OfflineErrorCallback;
            _credentialsBlobUpdated = CredentialsBlobUpdatedCallback;
            _connectionStateUpdated = ConnectionStateUpdatedCallback;
            _scrobbleError = ScrobbleErrorCallback;
            _privateSessionModeChanged = PrivateSessionModeChangedCallback;

            _callbacks = new Spotify.SpotifySessionCallbacks();
            _callbacks.LoggedIn = Marshal.GetFunctionPointerForDelegate(_loggedIn);
            _callbacks.LoggedOut = Marshal.GetFunctionPointerForDelegate(_loggedOut);
            _callbacks.MetadataUpdated = Marshal.GetFunctionPointerForDelegate(_metadataUpdated);
            _callbacks.ConnectionError = Marshal.GetFunctionPointerForDelegate(_connectionError);
            _callbacks.MessageToUser = Marshal.GetFunctionPointerForDelegate(_messageToUser);
            _callbacks.NotifyMainThread = Marshal.GetFunctionPointerForDelegate(_notifyMainThread);
            _callbacks.MusicDelivery = Marshal.GetFunctionPointerForDelegate(_musicDelivery);
            _callbacks.PlayTokenLost = Marshal.GetFunctionPointerForDelegate(_playTokenLost);
            _callbacks.LogMessage = Marshal.GetFunctionPointerForDelegate(_logMessage);
            _callbacks.EndOfTrack = Marshal.GetFunctionPointerForDelegate(_endOfTrack);
            _callbacks.StreamingError = Marshal.GetFunctionPointerForDelegate(_streamingError);
            _callbacks.UserinfoUpdated = Marshal.GetFunctionPointerForDelegate(_userinfoUpdated);
            _callbacks.StartPlayback = Marshal.GetFunctionPointerForDelegate(_startPlayback);
            _callbacks.StopPlayback = Marshal.GetFunctionPointerForDelegate(_stopPlayback);
            _callbacks.GetAudioBufferStats = Marshal.GetFunctionPointerForDelegate(_getAudioBufferStats);
            _callbacks.OfflineStatusUpdated = Marshal.GetFunctionPointerForDelegate(_offlineStatusUpdated);
            _callbacks.OfflineError = Marshal.GetFunctionPointerForDelegate(_offlineError);
            _callbacks.CredentialsBlobUpdated = Marshal.GetFunctionPointerForDelegate(_credentialsBlobUpdated);
            _callbacks.ConnectionStateUpdated = Marshal.GetFunctionPointerForDelegate(_connectionStateUpdated);
            _callbacks.ScrobbleError = Marshal.GetFunctionPointerForDelegate(_scrobbleError);
            _callbacks.PrivateSessionModeChanged = Marshal.GetFunctionPointerForDelegate(_privateSessionModeChanged);

            _callbacksHandle = Marshal.AllocHGlobal(CallbacksSize);
            Marshal.StructureToPtr(_callbacks, _callbacksHandle, true);
        }
Exemple #2
0
        private IntPtr AddCallbacks()
        {
            connectionErrorDelegate = ConnectionError;
            endOfTrackDelegate = EndOfTrack;
            getAudioBufferStatsDelegate = GetAudioBufferStats;
            logMessageDelegate = LogMessage;
            loggedInDelegate = LoggedIn;
            loggedOutDelegate = LoggedOut;
            messageToUserDelegate = MessageToUser;
            metadataUpdatedDelegate = MetadataUpdated;
            musicDeliveryDelegate = MusicDelivery;
            notifyMainThreadDelegate = NotifyMainThread;
            offlineStatusUpdatedDelegate = OfflineStatusUpdated;
            playTokenLostDelegate = PlayTokenLost;
            startPlaybackDelegate = StartPlayback;
            stopPlaybackDelegate = StopPlayback;
            streamingErrorDelegate = StreamingError;
            userinfoUpdatedDelegate = UserinfoUpdated;

            var callbacks = new libspotify.sp_session_callbacks
                            {
                                connection_error = connectionErrorDelegate.GetFunctionPtr(),
                                end_of_track = endOfTrackDelegate.GetFunctionPtr(),
                                get_audio_buffer_stats = getAudioBufferStatsDelegate.GetFunctionPtr(),
                                log_message = logMessageDelegate.GetFunctionPtr(),
                                logged_in = loggedInDelegate.GetFunctionPtr(),
                                logged_out = loggedOutDelegate.GetFunctionPtr(),
                                message_to_user = messageToUserDelegate.GetFunctionPtr(),
                                metadata_updated = metadataUpdatedDelegate.GetFunctionPtr(),
                                music_delivery = musicDeliveryDelegate.GetFunctionPtr(),
                                notify_main_thread = notifyMainThreadDelegate.GetFunctionPtr(),
                                offline_status_updated = offlineStatusUpdatedDelegate.GetFunctionPtr(),
                                play_token_lost = playTokenLostDelegate.GetFunctionPtr(),
                                start_playback = startPlaybackDelegate.GetFunctionPtr(),
                                stop_playback = stopPlaybackDelegate.GetFunctionPtr(),
                                streaming_error = streamingErrorDelegate.GetFunctionPtr(),
                                userinfo_updated = userinfoUpdatedDelegate.GetFunctionPtr()
                            };

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

            return callbacksPtr;
        }