Пример #1
0
        public static async Task <LyricModel> GetSongLyrics(string songName = "What Lovers Do", string singer = "Maroon 5")
        {
            // Set up the connection to api with supplied parameters
            string url = $"https://api.lyrics.ovh/v1/{ singer }/{ songName }";

            using (HttpResponseMessage responseMessage = await ApiHelper.ApiClient.GetAsync(url))
            {
                if (responseMessage.IsSuccessStatusCode)
                {
                    // Wait for the requested lyrics
                    LyricModel lyricModel = await responseMessage.Content.ReadAsAsync <LyricModel>();

                    return(lyricModel);
                }
                else
                {
                    throw new System.Exception(responseMessage.ReasonPhrase);
                }
            }
        }
Пример #2
0
        private async void SearchLyrics_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                LyricModel lyricModel = await LyricProcessor.GetSongLyrics(this.SongNameTextBox.Text, this.SingerTextBox.Text);

                if (string.IsNullOrEmpty(lyricModel.Lyrics))
                {
                    MessageBox.Show("Empty results returned");
                }
                else
                {
                    LyricsShowPane.Text = lyricModel.Lyrics;
                }
            }
            catch (System.Net.Http.HttpRequestException)
            {
                MessageBox.Show("No Internet Connection");
            }
        }