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

IOS :: how reproduce from /var/mobile/Containers/Data/Application/.../Library/NoCloud/... #46

Closed josaal17 closed 7 years ago

josaal17 commented 7 years ago

Hello,

The problem I have because at the end of the recording I want to show as a "Preview" of what I recorded, but it gives me error when playing it.

And it is only at the time of reproducing it, because at the time I upload it to the server with that same URL if it works.

I have seen in several forums that it is because it doesn't have permissions to use from that "url", which should be of a "tmp".

But I don't know how to solve it, or how to change that url for a temporary to be able to access it.

Thanks.

edimuj commented 7 years ago

Your issue doesn't contain enough information. This plugin cannot itself be used to playback audio, since its purpose is to capture the audio, so I guess you use some other way of playing back the preview? In which audio format do you capture the audio (Web audio buffers, Wav etc.), and how do you try to playback the preview (Web audio, Cordova-Plugin-Media etc.)? Some code would make it easier to determine what and why it doesn't work to playback the recording. If you save the audio to file with Cordova-Plugin-File, actual file paths should also be useful for debugging.

josaal17 commented 7 years ago

Thanks for the help,

If correct is right, I after testing I saw that the problem was presented in the other plugin where I stored the audio.

At first it is a bit confusing because one thinks that it records it I immediately store it in one direction but it is at that moment that another plugin enters to save it in some folder of the phone.

Use the plugin file and I had to change the folder in which I saved it. Because the folder in which I initially saved it did not allow it to be played on an html audio tag.

My code:

console.log ("Encoding WAV ..."); var encoder = new WavAudioEncoder (captureCfg.sampleRate, captureCfg.channels); encoder.encode ([audioDataBuffer]); console.log ("Encoding WAV finished"); var blob = encoder.finish ("audio / wav"); console.log ("BLOB created");

window.resolveLocalFileSystemURL (cordova.file.cacheDirectory, function (dir) {     var fileName = new Date (). YYYYMMDDHHMMSS () + ".wav";     dir.getFile (fileName, {create: true}, function (file)     {         file.createWriter (function (fileWriter)         {             fileWriter.write (blob);             sound = document.createElement ('audio');             sound.id = 'audio-player';             sound.controls = true;             sound.src = file.toNativeURL ();             sound.type = 'audio / wav';             sound.className = 'audiotosend_controls';             console.log ("File created!");             audioDataBuffer = [];             $ ("# audiotosend"). html (sound);         }, function ()         {             alert ("FileWriter error!");         });     }); });

I had to change the folder by: cordova.file.cacheDirectory

And the src get it with: file.toNativeURL ();

Thanks

edimuj commented 7 years ago

Ok, good that you managed to solve the problem. Big thanks for the thorough explanation, it may help somebody else having this problem.