我目前正在尝试使用ID3标记JavaScript库从URL链接中检索MP3文件信息。我正在寻找艺术家姓名,歌曲名称和专辑封面。
我的问题是我可以使用网址检索一些数据,但我有一个数组中的网址,一旦歌曲结束,我怎么能更新网址?此外,我即将展示的代码是错误的,因为它不允许我的默认音频播放器工作。
/**
* Loading the tags using XHR.
*/
//sample.mp3 sits on your domain
ID3.loadTags("https://dl.dropboxusercontent.com/s/hugnrhqxc04vbtb/3%20-%20Penicillin_281214300_soundcloud.mp3", function() {
showTags("https://dl.dropboxusercontent.com/s/hugnrhqxc04vbtb/3%20-%20Penicillin_281214300_soundcloud.mp3");
}, {
tags: ["title","artist","album","picture"]
});
/**
* Loading the tags using the FileAPI.
*/
function loadFile(input) {
var file = input.files[0],
url = file.urn || file.name;
ID3.loadTags(url, function() {
showTags(url);
}, {
tags: ["title","artist","album","picture"],
dataReader: ID3.FileAPIReader(file)
});
}
/**
* Generic function to get the tags after they have been loaded.
*/
function showTags(url) {
var tags = ID3.getAllTags(url);
console.log(tags);
document.getElementById('title').textContent = tags.title || "";
document.getElementById('artist').textContent = tags.artist || "";
document.getElementById('album').textContent = tags.album || "";
var image = tags.picture;
if (image) {
var base64String = "";
for (var i = 0; i < image.data.length; i++) {
base64String += String.fromCharCode(image.data[i]);
}
var base64 = "data:" + image.format + ";base64," +
window.btoa(base64String);
document.getElementById('picture').setAttribute('src',base64);
} else {
document.getElementById('picture').style.display = "none";
}
}
我的验收标准如下: