aadsm / jsmediatags

Media Tags Reader (ID3, MP4, FLAC)
Other
748 stars 128 forks source link

from input file with error("Offset 0 hasn't been loaded yet") #77

Closed smohammedyasin closed 6 years ago

smohammedyasin commented 6 years ago

hello, i'm try to get from input file with function, but i'm getting error ""Offset 0 hasn't been loaded yet"

html colde: <input type="file" id="file" onchange="loadFile(this)">

java script code:

function loadFile(input) {
      var myfile = input.files[0],
     console.log(myfile);
       jsmediatags.read(myfile, {
          onSuccess: function(tag) {
          console.log(tag);
            },
               onError: function(error) {
                   console.log(error);
            }
                });
  }

Please help Yasin

MartinDawson commented 6 years ago

@aadsm I'm also getting this error, everything was working fine before today.

Kalimba.zip

I'v uploaded the .mp3 file. I am on latest chrome version.

aadsm commented 6 years ago

Odd, I’ll try to get a look into it this weekend.

amartincolby commented 6 years ago

Following from above, I am seeing the same error. The majority of this text has been copied on Guthub as well. The onError event handler for the jsmediatags.open method receives an error object with properties:

type = "fileReader"

info = "Offset 0 hasn't been loaded yet"

Pseudo-code below.

I'm running this on my local workstation, with a Windows 7 OS running IIS. I've tested in Chrome v 61, and Firefox v 55. Same error in both.

As you can see, I'm trying to first send the file object (as a file) into the jsmediatags.read function. This results in the error detailed above.

I've commented out the code where, instead of the file object, I try sending in 1.) the complete local path to the file, 2.) the result of createObjectURL on the file object, as well as 3.) the file object's name property. These last 3 do not result in either an onSuccess or onError event being fired.

<script type="text/javascript" src="tagreader/jsmediatags.js"></script>

I am seeing the same error. The onError event handler for the jsmediatags.open method receives an error object with properties:

type = "fileReader"

info = "Offset 0 hasn't been loaded yet"

pseudo-code below.

I'm running this on my local workstation, with a Windows 7 OS running IIS. I've tested in Chrome v 61, and Firefox v 55. Same error in both.

As you can see, I'm trying to first send the file object (as a file) into the jsmediatags.read function. This results in the error detailed above.

I've commented out the code where, instead of the file object, I try sending in 1.) the complete local path to the file, 2.) the result of createObjectURL on the file object, as well as 3.) the file object's name property. These last 3 do not result in either an onSuccess or onError event being fired.

<script type="text/javascript" src="tagreader/jsmediatags.js"></script>

<input type="file" id="fileinput" onchange="window.handleLocalFiles(this.files)">

<script>

var gobjFileTags = null;

function handleLocalFiles(argFiles){
    if (argFiles && (argFiles.length > 0)){
        testTagReader(argFiles[0]);
    }
}

function testTagReader(objFile){
var objTagReader = null;

var strURL = "";
var strFileName = "";
var strLocalPath = "";

//  strFileName = objFile.name;
//  strURL = window.URL.createObjectURL(objFile);
//  var strLocalPath = "c:/users/public/public music/sample music/kalimba.mp3";

objTagReader = window.jsmediatags;

objTagReader.read(objFile, {
//  objTagReader.read(strLocalPath, {
//  objTagReader.read(strURL, {
//  objTagReader.read(strFileName, {
    onSuccess: function(tag){
        window.gobjFileTags = tag;
        window.readFileTags();
    },
    onError: function(objError){
        window.alert("objTagReader Error - type: " + objError.type + ", info: " + objError.info);
    }
});
}

function readFileTags(){
window.alert("readFileTags called");
}
andrewjcole commented 6 years ago

I'm having the same issue. Trying to use in a Chrome app.

chrisparton1991 commented 6 years ago

I've tracked this issue down. It was introduced in 7d5902a when some Flow errors were fixed. The culprit is BlobFileReader.js line 45, in which an ArrayBuffer is casted to a Number. This fails and we get the offset error.

Here's a screenshot showing the issue: casterror

I'll raise a PR to fix the issue shortly.

aadsm commented 6 years ago

@chrisparton1991 this is gold! I’ve been a bit strapped for time lately, so thank you so much for stepping in and finding the root cause! Will wait for your PR.