Search code examples
javascriptfileaudiotitlemeta

Get Audiofile Metainformation (Title/Genre) with Javascript


I want to get the title and the genre of an audiofile (by path) with javascript to display it on my web music player. Is this possible?

I looked for that a long time now and didn't find anything that could help me.


Solution

  • Metainformation of MP3 files is stored in ID3 containers. You can use JavaScript-ID3-Reader or similar library to decode it.

    <script src="id3-minimized.js"></script>
    <script>
    ID3.loadTags("filename.mp3", function() {
        var tags = ID3.getAllTags("filename.mp3");
        console.log(tags);
    });
    </script>
    

    Sample output

    {"version":"1.1","title":"Allegro from Duet in C Major","artist":"","album":"","year":"","comment":"","track":0,"genre":""}