File/blob object creation

680 views
Skip to first unread message

ragamuff...@gmail.com

unread,
Nov 15, 2018, 2:00:34 PM11/15/18
to DroidScript
Hey folks,

I'm coding a small audio player with a waveform (with wavesurfer.js) in droidscript.
A little trouble occurs when using listFolder(), as it returns filename(s) yet wavesurfer.js needs a file/blob object to generate a waveform, like <input type='file'> produces.
In chrome, one can call File(filepath), but in droidscript it is not supported.

Does anyone have any ideas / thoughts on solving this?

Thanks !

Dave

unread,
Nov 16, 2018, 8:28:44 AM11/16/18
to DroidScript

The following code works in DS, so you might be able to fill the first parameter with the data by reading it using the app.ReadFile() method and specifyting 'base64' option

var file = new File(["foo"], "foo.txt", {
  type: "text/plain",
});

ragamuff...@gmail.com

unread,
Nov 21, 2018, 2:18:33 PM11/21/18
to DroidScript
i tried reading the file with

audiodata = app.ReadFile(filePath, 'base64');
audiotrack = new File(audiodata, filePath, {
    type: "audio/mp3",});

...

wavesurfer.loadBlob(audiotrack);

this yields a Script Error:
Failed to construct 'File': The provided value cannot be converted to a sequence.
any ideas how to get the data properly?

thanks in advance!

ragamuff...@gmail.com

unread,
Nov 28, 2018, 11:40:49 AM11/28/18
to DroidScript
* bump * ..

I have no idea how to continue, apart from re-writing the program in java.
Seems such a shame, as everything is working apart from File I/O :((

BareK

unread,
Nov 28, 2018, 1:56:12 PM11/28/18
to DroidScript
You'd probably get more help providing a sample (in the form of an .spk) that reproduces your error.
This way one could (with little effort) try to make it work.
Having to guess what you did, create something from scratch, download wavesurfer etc. might discourage a lot of people.

ragamuff...@gmail.com

unread,
Dec 10, 2018, 8:55:18 PM12/10/18
to DroidScript
thanks barek!

finally here is the spk.

using the "select file" button will do everything as expected, while "select folder" yields the error.
actually, it should load the first file in the folder (for a start).

feel free to give it a fiddle..

im stuck on this one
test.spk

Steve Garman

unread,
Dec 11, 2018, 2:09:49 PM12/11/18
to DroidScript
When you've got a piece of code that does not work you need to look at what it is doing.

Looking at function callback_folderSelected(), your app.ListFolder code has a number of problems
  it is returning filenames without paths because you have not used the "fullPath" option

ListFolder() returns an array. You cannot just add 2 arrays together with a + sign
  For testing, I have just search for mp3

The following code goes as far as to produce a base64 string.

            list = app.ListFolder( fullPath, '.mp3',null,"fullpath");
           
var count = 0;
           
//for (audiotrack in list){
           
// var audiotrack = File.createFromFileName(list[0]);
            alert
(list[0])
            audiodata
= app.ReadFile(list[0], 'base64');
            alert
(audiodata);
Perhaps that will help you begin debugging the rest of the function
 
Reply all
Reply to author
Forward
0 new messages