forked from aadsm/JavaScript-ID3-Reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
71 lines (65 loc) · 2.01 KB
/
Copy pathindex.html
File metadata and controls
71 lines (65 loc) · 2.01 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Javascript ID3 Reader</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<script src="../dist/id3-minimized.js" type="text/javascript"></script>
</head>
<body>
<div>
<input type="file" id="file" onchange="loadFile(this)">
<p id="title"></p>
<p id="artist"></p>
<img id="picture" src="" alt= "picture extracted from ID3" />
</div>
<script>
/**
* Loading the tags using XHR.
*/
//sample.mp3 sits on your domain
ID3.loadTags("sample.mp3", function() {
showTags("sample.mp3");
},
{tags: ["title","artist","picture"]});
/**
* Loading the tags using the FileAPI.
*/
function loadFile(input) {
var file = input.files[0],
url = file.urn || file.name,
reader = new FileReader();
reader.onload = function(event) {
ID3.loadTags(url, function() {
showTags(url);
}, {
tags: ["title","artist","picture"],
dataReader: FileAPIReader(file)
});
};
reader.readAsArrayBuffer(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').innerHTML = tags.title;
document.getElementById('artist').innerHTML = tags.artist;
var image = tags.picture;
if (image) {
//Caution: old browsers (IE) don't implement Base64
//see N. Zakas for fallback:
//https://github.com/nzakas/computer-science-in-javascript/tree/master/encodings/base64
var base64 = "data:" + image.format + ";base64," + Base64.encodeBytes(image.data);
document.getElementById('picture').setAttribute('src',base64);
} else {
document.getElementById('picture').style.display = "none";
}
}
</script>
</body>
</html>