Danny O'Neill wrote:
I'm sure if someone who really knew outsystems were to spend 10mins, they could create a demo app which uses the audioplugin, takes the filepath returned by it and does SOMETHING, anything, to show how it can be used.
=========================================
This plugin is straightforward to use and it allows you to, out of the box, record an audio file, save it on the filesystem and even playback that audio file. This plugin does one thing and if you need further features you can leverage those features using other plugins or even build your own (See official documentation).
If you allow me the analogy, the good old tape recorders were awesome recording audio to tapes but they weren't able to distribute those tapes... it wasn't their responsibility to do so! In the same way, this plugin allows you to record audio and save the file on the filesystem and it is up to you, the developer, to do whatever you need to do with the resulting file. OutSystems mobile apps bring another dimension of requirements into play: mobile knowledge and specifically cordova. If for some reason the platform doesn't provide some functionality out of the box there's many ways to extend them: you could build custom plugins for mobile apps or even server side extensions but, of course, you do need to know how to...
This plugin returns a full path for the file but if you want to use that file in, lets say for example an audio tag, you need to prefix the scheme "file://". So, for a path:
"\/var\/mobile\/Containers\/Data\/Application\/916BB676-E259-43E7-A65A-E52088C7020F\/tmp\/OSAudioRecordings\/temp_002.mp4"
make sure that you prepend it with file scheme, like so:
file://\/var\/mobile\/Containers\/Data\/Application\/916BB676-E259-43E7-A65A-E52088C7020F\/tmp\/OSAudioRecordings\/temp_002.mp4"
Now you might encounter another problem if you try to use that path on an audio html element that is completely non-related to this plugin or any plugin whatsoever: you might break the Content-Security-Policies (CSP) when trying to load a local file directly into an element. Here's some documentation that might help.
If what you want is to save the audio file on the database instead of simply playing it on a audio element, you'll have to use the file plugin in order to read the bytes from the file and store on the database. I'm not entirely sure on the provided client actions of the File Plugin but the wrapped cordova plugin offers the necessary APIs to do so.
For example, the following would allow you to obtain a FileEntry instance for the audio file which you can use to read the content of the file as an ArrayBuffer:
window.resolveLocalFileSystemURL("file://\/data\/user\/0\/com.chuckytuh.audiorecorder.sampleapp\/files\/AudioRecords\/temp_3.mp4", function (fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function () {
// this.result is the loaded ArrayBuffer in this case
console.log("Successful file read: " + this.result);
// do whatever you need with the result, for example, save on the database!
};
reader.onloadstart = function () {
console.log("On load started");
};
reader.onerror = function (err) {
console.error(err);
};
reader.onprogress = function (e) {
console.log(e);
};
// there are other utility methods to read data, namely:
// reader.readAsBinaryString(file)
// reader.readAsDataURL(file)
reader.readAsArrayBuffer(file);
}, function (err) {
console.error(err);
});
}, function (err) {
console.error(err);
});
If you want to playback the file using the media plugin I am pretty sure that all you need is to prefix the path with the file:// scheme and you're all set..
Hope this sheds some light into a possible solution.
Cheers,
João Gonçalves