Parsing id3 data from local audio file in Firefox
I am developing Firefox addon
with SDK
, which lists the audio files on your computer with require("sdk/io/file").list()
.
I am creating an array of file paths using the method above and passing that array to the contentScript
attached to Panel
.
Then it Panel
iterates over the array and displays all the files it finds.
Now I am trying to use JavaScript-ID3-Reader , so I can read ID3
data from each file and display that data next to each file.
I am trying this (read local files) from within contentScript
eg.
var f = new File([""], "file:///home/user/audio.mp3");
ID3.loadTags("audio.mp3", function () {
var tags = ID3.getAllTags("audio.mp3");
console.log(tags.comment + " - " + tags.track + ", " + tags.lyrics);
}, {
dataReader: FileAPIReader(f)
});
But I get the output ..
undefined - undefined, undefined
/home/user/audio.mp3
contains the following data ID3
found from http://web.ist.utl.pt/antonio.afonso/www.aadsm.net/libraries/id3/ .
Artist
A Perfect Circle
Title
Annihilation
Album
eMOTIVe
Year
2004
Comment
Genre
Pop/Rock
Track
1/12
Lyrics
Here is another test I tried ...
function getID3 (file) {
var url = file.name;
console.log(url); // console.log: addon: /home/user/audio.mp3
ID3.loadTags(url, function () {
var tags = ID3.getAllTags(url);
console.log(tags); // console.log: addon: {}
console.log(tags.artist); // console.log: addon: null
}, {
dataReader: new FileAPIReader(file)
});
}
var f = new File([""], "file:///home/rob/audio.mp3", {type : "audio/mpeg"});
getID3(f);
Does anyone know what could be wrong with this? /home/user/audio.mp3
exists on the filesystem.
source to share
Are you sure you have these ID3 tags set in your audio.mp3 file? Try specifying your ID3 tags with console.log (tags) to see them all, and also try opening it with a desktop media player to see if the information shows up. Note that there are several different versions of ID3, so you might be using the wrong version as well.
source to share