ZhengCheng
ZhengCheng

Reputation: 1325

How to get <audio> tag information?

like title, subtitle, singer, Album, Bit rate etc..

wiki - MP3 tag infomation

wiki - ID3(mp3 metadata format)

I search a lot.. but I can't get answer.

only searched how to play,stop,reload audio..

browser not support that?

Upvotes: 7

Views: 11748

Answers (2)

HaBo
HaBo

Reputation: 14287

One more library available at https://github.com/aadsm/JavaScript-ID3-Reader

In its simplest form:

ID3.loadTags("filename.mp3", function() {
    var tags = ID3.getAllTags(filename);
    alert(tags.artist + " - " + tags.title + ", " + tags.album);
});

by specifying specific tags:

ID3.loadTags("filename.mp3", function() {
    var tags = ID3.getAllTags(filename);
    alert(tags.COMM.data + " - " + tags.TCON.data + ", " + tags.WXXX.data);
},
{tags: ["COMM", "TCON", "WXXX"]});

or even by specifying shortcuts instead of cryptic tags:

ID3.loadTags("filename.mp3", function() {
    var tags = ID3.getAllTags(filename);
    alert(tags.comment + " - " + tags.track + ", " + tags.lyrics);
},
{tags: ["comment", "track", "lyrics"]});

Demo here http://web.ist.utl.pt/antonio.afonso/www.aadsm.net/libraries/id3/#demo

Upvotes: 6

Turnerj
Turnerj

Reputation: 4278

It looks like you can with the right libraries! Reading ID3 tags with Javascript and here is the demo

Using the ID3.js library, your Javascript would be similar to:

// URL of the mp3 file (must be on the same domain!)
var file = "mymusicfile.mp3";
// define your own callback function
function mycallback() {
    // either call the ID3.getAllTags([file]) function which returns an object holding all the tags
    alert(
        "All tags in this file: " + ID3.getAllTags(file).toSource()
    );
    // or call ID3.getTag([file], [tag]) to get a specific tag
    alert(
        "Title: " + ID3.getTag(file, "title") + " by artist: " + ID3.getTag(file, "artist")
    );
}
ID3.loadTags(file, mycallback);

Based on the post in the first link I provided, it does not work in Opera browsers and is limited to ID3v1 which by the words of the poster:

"it's only capable of reading (the rather lacking) ID3v1 tags since these are very simple compared to the more fleshed out and robust ID3v2 tags"

Upvotes: 2

Related Questions