//Sets up the TextBlocks on the page by getting the song information and lyrics from the MusixMatch API private async void SetInfoViewModelAsync(String trackId) { Retriever retriever = new Retriever(); MusicFromIdRootObject music = await retriever.GetMusic(sharedData.CommonTrackId); LyricsRootObject lyrics = await retriever.GetLyrics(sharedData.TrackId); //Assigning TextBlock text to match song's info infoViewModel = new InfoViewModel() { AlbumName = music.message.body.track.album_name, TrackName = music.message.body.track.track_name, ArtistName = music.message.body.track.artist_name, LyricsString = lyrics.message.body.lyrics.lyrics_body, }; Title.Text = infoViewModel.TrackName + " by " + infoViewModel.ArtistName; AlbumName.Text = "Album: " + infoViewModel.AlbumName; Lyrics.Text = infoViewModel.LyricsString; if (Lyrics.Text.Equals("")) { Lyrics.Text = "No lyrics available"; } //Links to YT and Spotify YouTubeButton.NavigateUri = new Uri("https://www.youtube.com/results?search_query=" + Title.Text); SpotifyButton.NavigateUri = new Uri("https://open.spotify.com/search/results/" + Title.Text); }
//API call for getting the lyrics for a particular song after getting its track id public async Task <LyricsRootObject> GetLyrics(string trackId) { HttpClient httpClient = new HttpClient(); String apiUrl = $"http://api.musixmatch.com/ws/1.1/track.lyrics.get?track_id={trackId}&apikey={musixMatchKey}"; string responseString = await httpClient.GetStringAsync(apiUrl); LyricsRootObject results = JsonConvert.DeserializeObject <LyricsRootObject>(responseString); return(results); }