public SpotifyPlayer(SpotifyCredentials credentials) { this.credentials = credentials; this.playingThroughConnectAPI = false; this.isPaused = false; this.playlists = new List <IPlaylist>(); connectPlayback = new Thread(() => { while (alive) { if (playingThroughConnectAPI) { PlaybackContext playbackContext; if (credentials != null) { playbackContext = GetPlaybackContext(credentials.accessToken); if (playbackContext != null && this.isPaused) { logger.Info("Resuming playback since user unpaused"); this.isPaused = false; ResumePlayback(); } else if (playbackContext == null || !playbackContext.is_playing) { logger.Info("Starting playback or last song finished and playing next"); // check to make sure there are enough songs if (currentPlaylist.HasNextSong()) { PlayNextSong(); } } } } Thread.Sleep(2000); } }); alive = true; connectPlayback.Start(); this.tokenRefresher = new SpotifyTokenRefresher(credentials); this.tokenRefresher.Start(); }
public SpotifyTokenRefresher(SpotifyCredentials credentials) { this.credentials = credentials; SetRefresherThread(); }