【问题标题】:Get Thumbnail from mp3 file in c# xaml for windows phone 8.1在 c# xaml for windows phone 8.1 中从 mp3 文件中获取缩略图
【发布时间】:2015-07-10 23:45:50
【问题描述】:

我需要从 mp3 文件中获取缩略图。我实现了这个,但它从来没有捕捉到缩略图。我检查了使用 Windows 媒体播放器和 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好像有个bug,我搜了一夜,唯一能实现的方法就是这个

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;

但它也不起作用..

【问题讨论】:

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


    【解决方案1】:
    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 可移植的。 (抱歉,花了这么多时间)

    【讨论】:

    • 它不起作用,我读到了 windows phone 8.1 上的一个错误......我完全卡住了.. 请参阅我的编辑 2
    • 真的吗?你试过那个代码吗?对我来说,它为专辑收录的每首歌曲提供。我能做什么?
    • 我又检查了一遍,还是不行。它执行 try 代码(不抛出异常)但它没有通过 if 控制,我还是尝试执行该代码并将便笺图像作为封面艺术..
    • 它的工作原理谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    猜你喜欢
    • 2014-07-30
    • 1970-01-01
    • 2015-05-23
    • 1970-01-01
    • 2014-07-31
    • 1970-01-01
    • 1970-01-01
    • 2015-09-11
    • 1970-01-01
    相关资源
    最近更新 更多