var openFiles = function(event) {
var files = event.target.files;
var tracks = [];
for (i = 0; i < files.length; i++) {
a = get_tags(files[i])
console.log(a) // output is {}
}
}
var get_tags = function(file){
var useful_tags = {};
jsmediatags.read(file, {
onSuccess: function(tag) {
useful_tags = {
"type":tag["type"],
"title":tag["tags"]["title"],
"album":tag["tags"]["album"],
"artist":tag["tags"]["artist"],
"filename":file.name
};
},
onError: function(error) {
// handle error
console.log(error);
}
});
return useful_tags;
}
输出:{}
如果我要在console.log(useful_tags)
中放入onSuccess
,则会得到正确的对象,例如:{type: "ID3", title: "Money Trees", album: "good kid, m.A.A.d city", artist: "Kendrick Lamar", filename: "Kendrick Lamar - Money Trees.mp3"}
为什么get_tags在这里返回空对象?
我只想让get标签能够返回带有某些ID3标签和文件名的对象。