Base64 encode audio file for the web


#1

Hi,

i need to encode in base64 (data:audio/mp3;base64,…) an audio file that i have previously recorded and that is into the device application folder (running on android).

I know i should use the file-system component of nativescript, but i am not able to get the content of the file and then encode it (in a way similar to toFileUrl for images)…

I also posted the question on https://stackoverflow.com/questions/44129285/nativescript-convert-audio-file-to-base64 and there you can find a bit of the source code i am using.

How can i do that ?

Thanks in advance


How to base64 encode a file in NativeScript
#2

i also tried like this:

 sourceFile.readText().then(function (content) {
        const text = new java.lang.String(content);
        const data = text.getBytes("UTF-8");  
        const base64Encoded=android.util.Base64.encodeToString(data,android.util.Base64.NO_WRAP);
        console.log("encoded", base64Encoded);

        var adata="data:audio/mpeg;base64,"+b64;
});

but the resulting encoded string seems to be not playable via the web…