Cypheon
Cypheon

Reputation: 73

(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).

Upvotes: 5

Views: 880

Answers (2)

Gonzalo Carmenado
Gonzalo Carmenado

Reputation: 114

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.

Upvotes: 1

Cypheon
Cypheon

Reputation: 73

Well i managed to do this with the File-Path Plugin, it resolves the Path for your file in a way the File Plugin understands and is able to reach the file, then you just have to manipulate it the way you want.

Upvotes: 0

Related Questions