Kenson Nguyen
Kenson Nguyen

Reputation: 3

Trying to Extract Audio Metadata Javascript

I am very new to JavaScript, and am trying to extract audio metadata from files. To do this, I am trying to implement the audio-metadata library into my code (https://github.com/tmont/audio-metadata). However, when I try to run the example code, I keep getting the error saying "variable is not defined".

<!DOCTYPE html>
<html>
<head>
    <title>
        Kenson's Music Player
    </title>
    <link rel="stylesheet" href="player.css" type="text/css" />
    <script type="text/javascript" src="audio-metadata.min.js"></script>
</head>
<body>
<script type="text/javascript">
    var req = new XMLHttpRequest();
    req.open('GET', 'example.mp3', true);
    req.responseType = 'arraybuffer';

    req.onload = function() {
        var metadata = AudioMetaData.id3v2(req.response);
        /*
            {
                "TIT2": "Foobar",
                "title": "Foobar",
                "TPE1": "The Foobars",
                "artist": "The Foobars",
                "TALB": "FUBAR",
                "album": "FUBAR",
                "year": "2014",
                "TRCK": "9",
                "track": "9",
                "TSSE": "Lavf53.21.1",
                "encoder": "Lavf53.21.1"
            }
        */
    };

    req.send(null);
</script>
</body>

Upvotes: 0

Views: 4341

Answers (1)

Freyja
Freyja

Reputation: 40794

The documentation for audio-metadata seems to be incorrect, you should be using AudioMetadata instead of AudioMetaData.


Specifically, the script that generates the file audio-metadata.min.js that you're using can be found in the project's package.json file:

"build": "./node_modules/.bin/browserify -s AudioMetadata -e index.js --bare > audio-metadata.js"

Here -s AudioMetadata gives the name of the variable you should be using in the browser when using that package.

Upvotes: 1

Related Questions