从文件创建 MediaPlaybackItem 时 DisplayProperties 为空

DisplayProperties empty when creating a MediaPlaybackItem from file

我正在使用默认 MediaPlaybackItem 构造函数从文件创建播放列表:

songs = a.OfType<StorageFile>().Select(o => new MediaPlaybackItem(MediaSource.CreateFromStorageFile(o))).ToList();

但出于某种原因,此过程不会保留文件属性,这对于音乐播放软件来说非常重要。

供参考:

// This works just fine
var prop = await (_a as StorageFile).Properties.GetMusicPropertiesAsync();
// This doesn't.
var item = new MediaPlaybackItem(MediaSource.CreateFromStorageFile((StorageFile)_a));
item.GetDisplayProperties().MusicProperties;

项目的 DisplayProperties 以及附加的 MusicProperties 为空。

在项目创建过程中,有什么办法可以处理,还是我必须在创建项目后异步分配属性逐个?

foreach(var _a in a)
{
    var prop = await (_a as StorageFile).Properties.GetMusicPropertiesAsync();
    var item = new MediaPlaybackItem(MediaSource.CreateFromStorageFile((StorageFile)_a));
    var attached = item.GetDisplayProperties().MusicProperties;
    attached.AlbumArtist = prop.AlbumArtist;
    attached.AlbumTitle = prop.Album;
    // ...
    songs.Add(item);
}

干杯!

目前,我们只能像您所做的那样通过调用 GetDisplayProperties(), setting the data of the returned MediaItemDisplayProperties, and then calling ApplyDisplayProperties(MediaItemDisplayProperties) 以编程方式为媒体项提供元数据。

但是有一个名为 AutoLoadedDisplayProperties in MediaPlaybackItem 的新 prerelease 属性。通过设置此 属性,系统应自动从内容中加载元数据以显示在系统媒体传输控件中。但是,请注意 一些信息与预发布产品有关,在商业发布之前可能会进行大量修改。 Microsoft 对此处提供的信息不作任何明示或暗示的保证。

欢迎您加入 Windows Insider 并试用最新的 Insider Preview SDK。