0

I'm making a music player of sorts using c# and I've gotten songs to play/pause, fast forward/rewind and etc functions. The only thing I'm having trouble finding a solution to is displaying the song name, artist, album, and album art on a picturebox. I've heard of taglib# but I haven't found a clear way to implement/work with it. If there are other solutions I'm open to those as well.

I'm using the WindowsMediaPlayer class object too, but it doesn't display the album or artist, only the song name.

Karim O.
  • 1,325
  • 6
  • 22
  • 36

1 Answers1

3

Here's a code snippet that shows how you can get the information you're looking for.

    TagLib.File tagFile = TagLib.File.Create(@"C:\MySong.mp3");

    uint trackNumber = tagFile.Tag.Track;
    string songTitle = tagFile.Tag.Title;
    string artist = tagFile.Tag.AlbumArtists.FirstOrDefault();
    string albumTitle = tagFile.Tag.Album;
    uint year = tagFile.Tag.Year;
    string genre = tagFile.Tag.Genres.FirstOrDefault();

    MemoryStream ms = new MemoryStream(tagFile.Tag.Pictures[0].Data.Data);
    System.Drawing.Image albumArt = System.Drawing.Image.FromStream(ms);
Ben Allred
  • 4,544
  • 1
  • 19
  • 20
  • Getting the artwork image, throws an argument index out of range exception. Any idea why and how to solve it? – SepehrM Dec 06 '13 at 15:40
  • 1
    Probably because there is no album art. `tagFile.Tag.Pictures[0]` assumes there is at least one image. Unless you know for sure that there is a picture there, you need to do some additional checking, like `if (tagFile.Tag.Pictures.Any())`, for example. – Ben Allred Dec 06 '13 at 18:06