How can I get the cover of an mp3 file?

I have an mp3 file and when I read it with Windows Media Player it has an album art so I am wondering if there is a way to get this art in javascript or jQuery

+3


source to share


1 answer


Read more at this address: http://www.richardfarrar.com/embedding-album-art-in-mp3-files/

You want to use ID3 header where arists data is stored and more. Also images can be stored in these headers. This is probably also done in the mp3 files you have.

A library like https://github.com/aadsm/JavaScript-ID3-Reader can read this data from MP3 using Javascript.



Borrowed from example (Note: you need the library above before this code works):

 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";
      }
    }

      

+8


source







All Articles