(original stackoverflow issue)
I am using Ionic, and would like to record audio to a file, then do something with the file.
So first, I create the file:
await this.file.createFile(this.getFileDirectory(), this.getFileName(), true);
When it is ready, I create a new Media
instance:
this.currentRecording = this.media.create(this.getFilePath());
Attach a success and error listeners:
this.currentRecording.onSuccess.subscribe((e) => {
console.log(this.currentRecording.getDuration());
console.log(e);
});
this.currentRecording.onError.subscribe((err) => console.error(err));
Then I start recording:
this.currentRecording.startRecord();
After a few seconds, I stop recording, this.currentRecording.stopRecord()
, and the success callback is executed.
In the console, I now see
-1 // console.log(this.currentRecording.getDuration());
undefined // console.log(e);
Am I doing something wrong? How come it resolves to success, but with undefined
, and no duration?
EDIT: These are my path functions
private getFileDirectory() {
return this.file.documentsDirectory || this.file.dataDirectory;
}
private getFileName() {
return 'file.wav';
}
private getFilePath() {
return this.getFileDirectory() + this.getFileName();
}