Home > Ajax > dcomments.blogs.a.ajaxian  [ Add to favorite]  Print Message

Reading ID3 tags with JavaScript


Jacob Seidelin is up to more tricks, this time playing with the binary side of life and writing a library that can reading ID3 tags from MP3 files and such.

JAVASCRIPT:
  1.  
  2. // URL of the mp3 file (must be on the same domain!)
  3. var file = "mymusicfile.mp3"
  4.  
  5. // define your own callback function
  6. function mycallback() {
  7.  // either call the ID3.getAllTags([file]) function which returns an object holding all the tags
  8.  alert(
  9.   "All tags in this file: " + ID3.getAllTags(file).toSource()
  10.  )
  11.  
  12.  // or call ID3.getTag([file], [tag]) to get a specific tag
  13.  alert(
  14.   "Title: " + ID3.getTag(file, "title") + " by artist: " + ID3.getTag(file, "artist")
  15.  )
  16. }
  17.  
  18. ID3.loadTags(file, mycallback)
  19.  

You can view a demo at work or download the code.

Of course, Jacob realises that this doesn't make sense for many use cases:

Of course, one big disadvantage of doing this on the client in JavaScript is that the you need to download the entire MP3 file before the tags are available, so it might be better to stick to server-side solutions in many cases if all you need is the tag info.

Tue,
19 Aug 2008
Original article here