I am using Ionic, and would like to record audio to a file, then do something with the file.
Running on: Galaxy S4
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());
this.file.readAsArrayBuffer(this.getFileDirectory(), this.getFileName())
.then(file => console.warn(file))
});
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());
ArrayBuffer {} // console.warn(file);
Am I doing something wrong? How come it resolves to success, but with no file, and no duration?
Edit
Reproduction repository: https://github.com/AmitMY/ionic-media-record-repro
README has full instructions