Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Ionic) Cordova-file-plugin error when trying to read file

So, I'm currently trying to read an Audio file I just saved on the App's directory (Android) through the cordova file-plugin, but I keep getting the same error code 5, which stands for "ENCODING_ERR".

This is how I create the file and start recording

start() {
    this.filename = this.file.externalDataDirectory.replace(/file:\/\//g, '');
    this.mediaobject = this.media.create(this.filename + 'audioprofile' + '.3gp');
    this.mediaobject.startRecord(); 
}

This is how I stop recording and save the file

stop() {
 this.mediaobject.stopRecord();
 this.mediaobject.release(); 
...

And this is where I'm stuck: right after saving it, I need to have it as a String, so I'm try to read it ( alert(content) should show me that string)

stop() {  
this.mediaobject.stopRecord();
this.mediaobject.release();

this.storage.get("uid").then((id) => {

  try{
  this.file.readAsDataURL(this.filename,'audioprofile'+'.3gp').then((filecontent)=>{
  alert(filecontent);
},(err)=>{
    alert(err.code);
  })
  } `

After some research I found out it PROBABLY means I'm not giving the right path for it, but I've tried everything, any combinations of 'filename' and 'filepath' were made, even adding the prefix removed on start().

I want to know if someone managed to read a file with this cordova plugin and if you did, please help me out.

Thanks in advance, this is my first post here \o/ (although I've always used the website, love u guys).

like image 612
Cypheon Avatar asked Nov 08 '22 14:11

Cypheon


1 Answers

i had the same problem. I solved it giving this path:

this.media.create(this.file.externalDataDirectory + this.nameFile);

I dont know why but this.file.readAsDataURL cant read the file if u save it deleting /file:
Remember change the path in all your methods.

like image 188
Gonzalo Carmenado Avatar answered Nov 14 '22 21:11

Gonzalo Carmenado