<script src="jsmediatags.min.js"></script>
<body>
<form>
<input id="$inputTypeFile" type="file" name="audio" accept="audio/*">
<input type="submit" name="submit" value="add music"/>
</form>
<img src="" alt="" width="500px" height="500px">
</body>
<script>
// From File
$inputTypeFile.addEventListener("change", function(event) {
var file = event.target.files[0];
jsmediatags.read(file, {
onSuccess: function(tag) {
console.log(tag);
var picture = tag.tags.picture; // create reference to track art
var base64String = "";
for (var i = 0; i < picture.data.length; i++) {
base64String += String.fromCharCode(picture.data[i]);
}
var imageUri = "data:" + picture.format + ";base64," + window.btoa(base64String);
document.querySelector('img').src=imageUri;
// use ajax to upload tag info, or create some new form elements
},
onError: function(error) {
console.log(error);
}
});
}, false);
</script>