aadsm / JavaScript-ID3-Reader

ID3 tags reader in JavaScript (ID3v1, ID3v2 and AAC)

Home Page:http://www.aadsm.net/libraries/id3/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tags are empty for local file, reading from within firefox addon

bobbyrne01 opened this issue · comments

Any idea why this is not working for local files within a firefox addon?

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([""], "/home/user/audio.mp3");
getID3(f);

On filesystem ..

rob@work:~$ pwd
/home/rob
rob@work:~$ ls audio.mp3 
audio.mp3

Using your test page: http://web.ist.utl.pt/antonio.afonso/www.aadsm.net/libraries/id3/, it prints the following output for the local file ..

Artist
    A Perfect Circle
Title
    Annihilation
Album
    eMOTIVe
Year
    2004
Comment
Genre
    Pop/Rock
Track
    1/12

I'm not sure how permissions work in Firefox addons but I would expect at least to have to use the file:// protocol like file:///home/user/audio.mp3.
Are you sure the addons are able to read the user's FS just like that?

Yeah, I have similar code to actually play an audio file from local FS which works fine e.g

// document.getElementById('player') is an <audio> element
document.getElementById('player').src = 'file:///home/user/audio.mp3';
document.getElementById('player').play();

Most recently I've 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 reader = new FileReader();

reader.onload = function(){
    var dataURL = reader.result;
    getID3(reader.result);
};

reader.readAsDataURL(new File([""], "file:///home/user/audio.mp3"));

Which outputs this error:

id3-minimized.js, line 9: TypeError: Argument 1 of FileReader.readAsBinaryString is not an object.

It seems that you're giving a dataURL to the FileAPIReader constructor. You should give the File object directly, the FileAPIReader will to all the necessary reading.
So I guess it should be as simple as getID3(new File([""], "file:///home/user/audio.mp3").

@aadsm im going to close this, as i've got it working outside of firefox so its not due to the library itself. Thanks though!