-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathid3reader.js
More file actions
47 lines (44 loc) · 1.24 KB
/
id3reader.js
File metadata and controls
47 lines (44 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Loading the tags using XHR.
*/
//sample.mp3 sits on your domain
ID3.loadTags("dancin.mp3", function() {
showTags("dancin.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: 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";
}
}