edimuj / cordova-plugin-audioinput

This iOS/Android Cordova/PhoneGap plugin enables audio capture from the device microphone, by in near real-time forwarding audio to the web layer of your application. A typical usage scenario for this plugin would be to use the captured audio as source for a web audio node chain, where it then can be analyzed, manipulated and/or played.
https://github.com/edimuj/app-audioinput-demo
MIT License
161 stars 88 forks source link

stop() callback invoked when file doesn't exist #82

Open giorgiobeggiora opened 5 years ago

giorgiobeggiora commented 5 years ago

The file is not available in the stop() callback, so you need to check if the file exists using a loop that interrupts when the file become available.

Note that if you're using always the same file name you need to always delete the file before to run start() again, otherwise you will use the previous audio file.

const captureCfg = { fileUrl: urlToMyLocalFile }
audioinput.start(captureCfg);
setTimeout(stopRecording, 1000);
function stopRecording () {
  audioinput.stop(function(url){
    console.log(url); // value is "OK"
    window.resolveLocalFileSystemURL(urlToMyLocalFile, function (fileEntry) {
      console.log('file found'); // this doesn't trigger
    }, err => {
      console.log(err.code); // value is 1 ---> FileError.NOT_FOUND_ERR
    });
  });
}
artorralbaiii commented 5 years ago

Try to have a setTimeOut before you call the window.resolveLocalFileSystemURL.

Because there is a short delay on creating the physical file so when you trying to locate the file, it is not yet created.

giorgiobeggiora commented 5 years ago

of course that's a possible solution, but I think it's a plugin's job wait for the file creation, and then fire the callback: it should not be a developer's implementation. At least, please write about the delay in the documentation!

edimuj commented 5 years ago

Yes, I agree @giorgiobeggoria, it is something that would be handled by the plugin. Please send a PR with your fix and I'll merge it.

giorgiobeggiora commented 5 years ago

the problem is that I don't know Java nor any other native language... well, it's time to learn them :)