public static void PlayPause() { SpotifyLocalAPI _spotify = new SpotifyLocalAPI(); if (!_spotify.Connect()) { return; } StatusResponse status = _spotify.GetStatus(); if (status == null) { return; } if (status.Playing) { _spotify.Pause(); } else { _spotify.Play(); } _spotify = null; }
private async void ClientListener(string clientKey, CancellationToken token) { var spotify = new SpotifyLocalAPI(); var redisClient = new RedisClient(clientKey); if (!TryConnect(spotify)) { return; } while (true) { if (token.IsCancellationRequested) { redisClient.Delete($"Connected:{CurrentInstance}"); return; } var status = spotify.GetStatus(); var track = redisClient.Get<string>("TrackChange"); if (status.Track.TrackResource.Uri != track) { spotify.PlayURL(track); } var state = redisClient.GetBoolean("PlayStateChange"); if (status.Playing != state) { if (state != null && state == true) { spotify.Play(); } else if (state != null) { spotify.Pause(); } } UpdateUsers(redisClient); await Task.Delay(WaitMillisecondsDelay); } }