Question

I've done some research on the subject, but can't get a clear answer with how to go about doing this. I have tried the following method:

<script type="text/javascript" src="../binaryajax/binaryajax.js" ></script>
<script type="text/javascript" src="id3.js" ></script>

var file = "mymusicfile.mp3";
// define your own callback function
function mycallback() {
// either call ID3.getAllTags([file]) function to return 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);

The first method, (getAllTags) doesn't allow my script to run, and the second method returns null for both title and artist on all of my mp3's.

Source of Info: http://blog.nihilogic.dk/2008/08/reading-id3-tags-with-javascript.html

I know these methods are using ID3(v1), so that may be the problem. Either that, or I suppose it's possible by mp3's don't contain ID3 information. But if anyone could provide some insight into how to do this, or how to identify if my mp3's contain ID3 info and whether it's v1 or v2 would be great.

Edit: I should say, I'm accessing the files via Blob URL's because the app that I'm developing let's the user select a directory on their computer and then queries the files for media files. In doing this, you can't access the absolute path of the file, but you still can access the file information and use the file.

Était-ce utile?

La solution

For others to use: this worked quite well for me :)

github.com/aadsm/JavaScript-ID3-Reader/tree/master/src use the project repository

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top