Implementing taglib# into a c# music player

721 views Asked by At

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.

1

There are 1 answers

2
Ben Allred On BEST ANSWER

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);