I’m building an app that needs to record sound every time a certain disciple count is reached, I’m using DBmeter plugin which runs in a loop so every time let’s say it reaches 80 disciples it runs functions inside the loop without waiting for other function to finish.
I tried using Promises but it doesn’t seem to work, and I tried tried to delete the DBmeter Instance which also doesn’t work (it records one and when I try to restart the DBmeter instance it stops working)
the code i’m using:
startStreaming(){
console.log('rerun');
this.subscription = this.dbMeter.start().subscribe(
data => {
this.count = Number(data);
console.log(this.count);
if(!this.ispaused && this.count >= 85){
console.log('im in');
this.triggered = true;
this.ispaused = true;
this.handleDecp()
}
}
);
handleDecp(){
this.triggered = true;
this.ispaused = true;
let log = '';
log += this.count.toString() + ' - ' + this.getTime();
this.logsService.addLog(log).then(() => {
console.log(log);
});
console.log('test');
this.recordNoise().then(() => {
console.log('working ok');
return;
});
return;
}
recordNoise(){
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.dataDirectory.replace(/file:\/\//g, '') + this.fileName;
// const fi: MediaObject = this.media.create('test.mp3');
const file: MediaObject = this.media.create(this.fileName);
file.startRecord();
window.setTimeout(() => file.stopRecord(), 7000);
this.triggered = false;
this.ispaused = false;
return;
}