سؤال

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.

هل كانت مفيدة؟

المحلول

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);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top