public AvailabeDevices GetSpotifyDevices() { this.CheckOrRefreshToken(); AvailabeDevices spotifyDevices = this._spotifyBase.SpotifyWebApi.GetDevices(); return(spotifyDevices); }
private static async Task StashCurrentSpotifySettings(SpotifyWebAPI api, AvailabeDevices devices) { var currentDevice = devices.Devices.Where(n => n.IsActive).FirstOrDefault(); if (currentDevice != null) { memoryCache.Set("PreviousDevice", currentDevice); memoryCache.Set("PreviousContext", await api.GetPlayingTrackAsync()); memoryCache.Set("PreviousVolume", currentDevice.VolumePercent); memoryCache.Remove("TrackOffset"); var t = await api.GetPlaybackAsync(); var profile = await api.GetPrivateProfileAsync(); switch (t.Context?.Type.ToLowerInvariant()) { case "playlist": { // Try and find the current track position in the current playlist string playlistId = t.Context.Uri.Remove(0, t.Context.Uri.LastIndexOf(':') + 1); var playlistTracks = await api.GetPlaylistTracksAsync(playlistId); for (int i = 0; i < playlistTracks?.Items?.Count; i++) { if (playlistTracks.Items[i].Track.Id == t.Item.Id) { memoryCache.Set("TrackOffset", i); break; } } break; } case "album": { if (!t.Context.Uri.Contains("collection", StringComparison.InvariantCultureIgnoreCase)) { memoryCache.Set("TrackOffset", t.Item.TrackNumber - 1); } break; } default: break; } } }
public IEnumerable <ResponseMessage> GetAvialableSpotifyDevices(IncomingMessage message, IValidHandle matchedHandle) { string reply; AvailabeDevices spotifyDevices = this._spotifyPlugin.GetSpotifyDevices(); if (spotifyDevices.HasError()) { reply = "No Devices where found"; } else { reply = "Please choose a device to use : set device deviceID"; foreach (Device spotifyDevice in spotifyDevices.Devices) { yield return(message.ReplyToChannel($"Spotify device name : {spotifyDevice.Name} | type : {spotifyDevice.Type} | ID : {spotifyDevice.Id} ", (Attachment)null)); } } yield return(message.ReplyToChannel(reply, (Attachment)null)); }