internal static EchoSong FromJson(JToken json) { if (json == null) throw new ArgumentException("Json can not be null."); var result = new EchoSong(); result.Id = json["id"].Value<string>(); result.Title = json["title"].Value<string>(); result.ArtistId = json["artist_id"].Value<string>(); result.ArtistName = json["artist_name"].Value<string>(); return result; }
internal static EchoSong FromJson(JToken json) { if (json == null) { throw new ArgumentException("Json can not be null."); } var result = new EchoSong(); result.Id = json["id"].Value <string>(); result.Title = json["title"].Value <string>(); result.ArtistId = json["artist_id"].Value <string>(); result.ArtistName = json["artist_name"].Value <string>(); return(result); }
private static void PlaySong(EchoSong song) { var audio = new Audio() { Title = song.Title, Artist = song.ArtistName }; _currentSong = song; AudioService.Play(audio); AudioService.Playlist.Insert(0, audio); //AudioService.SetCurrentPlaylist(new[] { audio }, true); }
public async Task <Tuple <string, EchoSong> > DynamicCreate(EchoPlaylistType type = EchoPlaylistType.ArtistRadio, IEnumerable <string> artistIds = null, IEnumerable <string> artists = null, IEnumerable <string> songIds = null, IEnumerable <string> genres = null, IEnumerable <string> trackIds = null, bool returnTrack = true) { var parameters = new Dictionary <string, object>(); switch (type) { case EchoPlaylistType.Artist: case EchoPlaylistType.ArtistDescription: throw new ArgumentOutOfRangeException("type", "Basic playlist doesn't support artist and artist-description type."); case EchoPlaylistType.ArtistRadio: parameters.Add("type", "artist-radio"); break; case EchoPlaylistType.SongRadio: parameters.Add("type", "song-radio"); break; case EchoPlaylistType.GenreRadio: parameters.Add("type", "genre-radio"); break; } if (artistIds != null) { parameters.Add("artist_id", artistIds); } if (artists != null) { parameters.Add("artist", artists); } if (songIds != null) { parameters.Add("song_id", songIds); } if (genres != null) { parameters.Add("genre", genres); } if (trackIds != null) { parameters.Add("track_id", trackIds); } if (returnTrack) { parameters.Add("results", "1"); } parameters.Add("api_key", _echonest.ApiKey); var response = await new EchoRequest(new Uri(EchoConst.MethodBase + "playlist/dynamic/create"), parameters).Execute(); string sessionId = null; EchoSong track = null; var token = response.SelectToken("response.songs"); if (token != null && token.HasValues) { track = token.Select(EchoSong.FromJson).FirstOrDefault(); } if (response["response"]["session_id"] != null) { sessionId = response["response"]["session_id"].Value <string>(); } return(new Tuple <string, EchoSong>(sessionId, track)); }