【问题标题】:How to get the file name and id3 tags of an mp3 file in a Windows 8 metro app using javascript?如何使用 javascript 在 Windows 8 Metro 应用程序中获取 mp3 文件的文件名和 id3 标签?
【发布时间】:2012-10-19 20:34:37
【问题描述】:

我只想列出音乐库中的文件。我想列出文件的路径、作者和标题。 Windows 8 Javascript API 提供了简洁的异步函数。我的问题是我无法将变量传递给函数,因此我无法识别回调函数中的文件。到目前为止,这是我所拥有的:

var musicLibrary = Windows.Storage.KnownFolders.musicLibrary;
musicLibrary.getFilesAsync().then(function (resultLibrary) {
 for (var i = 0; i < resultLibrary.length; i++) {
  var path = resultLibrary[i].path;
  resultLibrary[i].properties.getMusicPropertiesAsync().then(function (musicProperties) {
  $("#list").append('<li>'+ musicProperties.artist + ', ' + musicProperties.title + '</li>');
}
});

如您所见,我可以检索所有信息,但不能将它们放在一个列表项中。谁能告诉我这是怎么做到的?谢谢!

【问题讨论】:

    标签: javascript windows-8 microsoft-metro winjs


    【解决方案1】:

    您可以在 javascript 中使用closure

    var musicLibrary = Windows.Storage.KnownFolders.musicLibrary;
    musicLibrary.getFilesAsync().then(function (resultLibrary) {
    
        for (var i = 0; i < resultLibrary.length; i++) {
        (function(song){
            var path = song.path;
            song.properties.getMusicPropertiesAsync().done(function (musicProperties) {
                $("#list").append('<li>' + song.path + musicProperties.artist + ', ' + musicProperties.title + '</li>');
            })
        })(resultLibrary[i]);
        }
    });
    

    【讨论】:

    • 它工作正常,谢谢!我现在要研究一下关闭的东西。
    猜你喜欢
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    相关资源
    最近更新 更多