从c#xaml for windows phone 8.1获取mp3文件的缩略图

时间:2015-07-10 23:45:50

标签: c# xaml windows-phone-8.1 windows-phone runtime

我需要从mp3文件中获取缩略图。我实现了这个,但它永远不会抓住缩略图。我检查了使用Windows Media Player和xbox音乐(在手机上)打开图像的存在,但我无法在我的应用程序中检索它们。请帮忙

async private void ThumbnailFetcher(StorageFile file)
    {

        if (file != null)
        {
            const ThumbnailMode thumbnailMode = ThumbnailMode.MusicView;
            const uint size = 100;



            using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(thumbnailMode, size))
            {

                if (thumbnail != null && thumbnail.Type == ThumbnailType.Image)
                {
                   this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        BitmapImage thumbnailImage = new BitmapImage();//image used for display
                        thumbnailImage.SetSource(thumbnail);
                        CurrentAlbumArt.Source = thumbnailImage;


                        Debug.WriteLine("true");
                    });

                }
                else
                {
                    Debug.WriteLine("False");
                }
            }
        }

    }

P.s总是假的。

似乎Windows Phone 8.1上有一个错误,我整夜都在搜索,我唯一能实现的方法就是这个

var fileStream = await file.OpenStreamForReadAsync();

        var TagFile = File.Create(new StreamFileAbstraction(file.Name, fileStream, fileStream));
        // Load you image data in MemoryStream
        var tags = TagFile.GetTag(TagTypes.Id3v2);


        IPicture pic = TagFile.Tag.Pictures[0];
        MemoryStream ms = new MemoryStream(pic.Data.Data);
        ms.Seek(0, SeekOrigin.Begin);


            bitmap.SetSource(ms.AsRandomAccessStream());
            AlbumArt.Source = bitmap;

但它也不起作用..

1 个答案:

答案 0 :(得分:0)

var filestream = await receivedFile.OpenStreamForReadAsync();
            var tagFile = File.Create(new StreamFileAbstraction(receivedFile.Name, filestream, filestream));
            var tags = tagFile.GetTag(TagLib.TagTypes.Id3v2);
            var bin = (byte[])(tags.Pictures[0].Data.Data);
            MemoryStream ms = new MemoryStream(bin);
           await bitmapImage.SetSourceAsync(ms.AsRandomAccessStream());
AlbumArt.Source=bitmapImage;

使用此和taglib portable。 (抱歉花了这么多时间)