GetMusicPropertiesAsync 在 Windows Phone 8.1 上返回的持续时间不正确

本文关键字:返回 持续时间 不正确 Windows Phone GetMusicPropertiesAsync | 更新日期: 2023-09-27 18:33:17

我正在尝试构建一个音乐选择器来在我的应用程序中构建播放列表,我从媒体库中选择文件

await KnownFolders.MusicLibrary.GetFilesAsync(CommonFileQuery.OrderByName)

,然后为每个文件选择音乐属性:

var info = await Task.WhenAll(files.Select(async f => new 
    { file = f, m = await f.Properties.GetMusicPropertiesAsync() }));

出于某种原因,Duration 属性对于我的媒体完全关闭 - 它实际上是一个小 10000 倍的数字,因此对于持续时间为 1:10:02(4202 秒)的媒体文件,它报告的持续时间为 0.420224 秒。

媒体的实际毫秒数在时间跨度内存储在 Ticks 中。因此,要获得媒体的真实持续时间,我必须重新计算持续时间为

item.Duration = TimeSpan.FromMilliseconds(item.Duration.Ticks)

我在文档中遗漏了某些内容吗?Docs for MusicProperties.Duration声明它Gets the duration of the song in milliseconds.并且它是一个TimeSpan,所以这是一个错误吗?

GetMusicPropertiesAsync 在 Windows Phone 8.1 上返回的持续时间不正确

我也发现了这个错误。可能的解决方案是从路径加载文件(但可能更慢):

StorageFile fileShadow = await StorageFile.GetFileFromPathAsync(file.Path);
var musicProps = await fileShadow.Properties.GetMusicPropertiesAsync();
var duration = musicProps.Duration;//Valid duration