Get Albumart in .mp3 file for Windows Store App

2019-04-29 16:01发布

How can i get the AlbumArt image in the mp3 file? I am developing Windows Store app with c#.

MusicProperties class gives me Album name artist name vs. But it cant give me albumart.

3条回答
一纸荒年 Trace。
2楼-- · 2019-04-29 16:22

I found a solution here How to: Get IDE Tags and Thumbnails of a file

var bitmapImage = new BitmapImage();

//Get Album cover
using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.MusicView, 300))
{
     if (thumbnail != null && thumbnail.Type == ThumbnailType.Image)
     {
         bitmapImage.SetSource(thumbnail);
     }
     else
     {
         //Error Message here
     }
}
查看更多
来,给爷笑一个
3楼-- · 2019-04-29 16:25

here's my quick and short solution for that problem thirding TagLib#: (http://taglib.github.io/)

using TagLib;
var file = TagLib.File.Create(filename);
var bin = (byte[])(file.Tag.Pictures[0].Data.Data);
imageBox.Image = Image.FromStream(new MemoryStream(bin));
查看更多
男人必须洒脱
4楼-- · 2019-04-29 16:36

Check out MSDN sample to show thumbnail of any file. It also consists how to retrieve the album art.

File and folder thumbnail sample

If you want to save the album art check out How to store save Thumbnail image in device in windows 8 metro apps c#

UPDATE 1

MediaFile is StorageFile. ImageControl is <Image ... />

using (StorageItemThumbnail thumbnail = await MediaFile.GetThumbnailAsync(ThumbnailMode.MusicView, 300))
{
    if (thumbnail != null && thumbnail.Type == ThumbnailType.Image)
    {
        var bitmapImage = new BitmapImage();
        bitmapImage.SetSource(thumbnail);
        ImageControl.Source = bitmapImage;
    }
}
查看更多
登录 后发表回答