Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
greetings,
I am a newbie. I am designing a small windows forms application for editing the id3 tags in mp3 files. I am using TagLib# for this purpose. I am able to search for the album art of the song from the Last.fm API and load it into a picture box for the user to see using a webrequest. But when I try to apply the Image to the song using it's URL then it shows the error "cannot use URL".
Here's My code.
PLEASE HELP!!
C#
 private void searcher_Click(object sender, EventArgs e)
       {
           string ApiKey = "****************************";
           string LastFMLogin = "**************";
           Lastfm.Services.Session session = new Lastfm.Services.Session(ApiKey,LastFMLogin);
           Lastfm.Services.Artist lArtist = new Lastfm.Services.Artist(artist2.Text,session);
           Lastfm.Services.Album lAlbum = new Lastfm.Services.Album(lArtist,album2.Text,session);
           textBox5.Text = AbsUrlOfArt(album2.Text, artist2.Text);
           p5.ImageLocation = textBox5.Text;

       }

 private void set_Click(object sender, EventArgs e)
       {

           TagLib.File f6 = TagLib.File.Create(path2[songlist.SelectedIndex]);
           IPicture[] pictures = new IPicture[1];
           pictures[0] = new Picture(p5.ImageLocation);
           f6.Tag.Pictures = pictures;
       }

public static string AbsUrlOfArt(string album, string artist)
       {
           string ApiKey = "****************************";
           string LastFMLogin = "**************";
           Lastfm.Services.Session session = new Lastfm.Services.Session(ApiKey,LastFMLogin);
           Lastfm.Services.Artist lArtist = new Lastfm.Services.Artist(artist, session);
           Lastfm.Services.Album lAlbum = new Lastfm.Services.Album(lArtist, album, session);
           return lAlbum.GetImageURL(AlbumImageSize.ExtraLarge);


       }

       public static System.Drawing.Image AlbumArt(string album, string artist)
       {
           Stream stream = null;
           try
           {

               WebRequest req = WebRequest.Create(AbsUrlOfArt(album, artist));
               WebResponse response = req.GetResponse();
               stream = response.GetResponseStream();
               Image img = Image.FromStream(stream);
               return img;
           }

           catch (Exception e)
           {
               return null;
           }

           finally
           {
               if (stream != null)
                   stream.Dispose();
           }

       }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900