How to get <audio> tag information?

后端 未结 2 1965
闹比i
闹比i 2020-12-31 23:28

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 answ

相关标签:
2条回答
  • 2020-12-31 23:50

    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"

    0 讨论(0)
  • 2021-01-01 00:08

    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

    0 讨论(0)
提交回复
热议问题