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

时间:2014-12-06 11:34:13

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

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

await KnownFolders.MusicLibrary.GetFilesAsync(CommonFileQuery.OrderByName)

然后使用以下选项为每个文件选择音乐属性:

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

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

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

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

我遗漏了文档中的内容吗? MusicProperties.Duration的文档声明它是Gets the duration of the song in milliseconds.而它是TimeSpan,这是一个错误吗?

1 个答案:

答案 0 :(得分:0)

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

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