I have created the function to save and record and stop the recording, but it does not work, it creates the file but does not store the recording, the file weighs 0B.
I use a xiaomi mobile with android 10.
I have the following code
startRecord() {
if (this.platform.is('ios')) {
this.fileName = 'record' + new Date().getDate() + new Date().getMonth() + new Date().getFullYear() + new Date().getHours() + new Date().getMinutes() + new Date().getSeconds() + '.mp3';
this.filePath = this.file.documentsDirectory.replace(/file:\/\//g, '') + this.fileName;
this.audio = this.media.create(this.filePath);
} else if (this.platform.is('android')) {
this.fileName = 'record'+new Date().getDate()+new Date().getMonth()+new Date().getFullYear()+new Date().getHours()+new Date().getMinutes()+new Date().getSeconds()+'.mp3';
this.filePath = this.file.externalDataDirectory.replace(/file:\/\//g, '') + this.fileName;
this.audio = this.media.create(this.filePath);
this.audio.startRecord();
}
this.recording = true;
}
stopRecord() {
this.base64.encodeFile(this.filePath).then(
(base64: any) => {
let dataAudio = base64.substr(34, base64.length);
let x = base64.substr(13, base64.length);
x = "data:audio/mpeg;base64" + x;
console.log("base64",x);
this.dataAudios.push(this.sanitizer.bypassSecurityTrustUrl(x));
this.dataUpload.push(dataAudio);
}, err=>{
console.log("base64 err", err);
});
this.recording = false;
}
Additional Information
Ionic:
Ionic CLI : 5.4.16 (/usr/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 5.3.5
@angular-devkit/build-angular : 0.1000.8
@angular-devkit/schematics : 10.0.8
@angular/cli : 10.0.8
@ionic/angular-toolkit : 2.3.3
Cordova:
Cordova CLI : 10.0.0
Cordova Platforms : android 9.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 18 other plugins)
Utility:
cordova-res : 0.15.1
native-run (update available: 1.2.2) : 0.2.9
System:
Android SDK Tools : 26.1.1 (/root/Android/Sdk)
NodeJS : v12.19.0 (/usr/bin/node)
npm : 6.14.8
OS : Linux 4.15
1 post - 1 participant