Skip to content Skip to sidebar Skip to footer

Phonegap / Cordova - Read File As Text From Temporary Directory

i am using the cordova media plugin to record .wav audio samples. Actually i am able to record them but i can't find the way to get the already created file content. If i do: // Re

Solution 1:

Media plugin is by it's description meant to

provide the ability to record and play back audio files

So I suppose it isn't going to give you the raw data. However, as you know the URI of your audio file, use the File plugin to fetch the data from it.

Update

If you want to upload the file, refer to here.

If you instead want to get your audio file as Base64 encoded String, refer to here.

That is quite a long code and has AngularJS in it, so I took the essential parts as a summary here for you

functionOnFileEntry(file){
  var reader = newFileReader();
  reader.onloadend = function(evt) {
      var image = evt.target.result;
      var base64Data  =   image.replace(/^data:audio\/mpeg;base64,/, "");
      base64Data  +=  base64Data.replace('+', ' ');
  };
  reader.readAsDataURL(file);
}

functionOnGetFile(fileEntry){
  fileEntry.file(OnFileEntry, fail);
}

functionOnFileSystem(fileSystem){
  fileSystem.root.getFile(recordName, null, OnGetFile, fail);
}

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, OnFileSystem, fail);

What you need to change here is the recordName to match your src attribute's value.

Is that enough for you, or is there something else I can help you with?

Post a Comment for "Phonegap / Cordova - Read File As Text From Temporary Directory"