processing / processing-sound

Audio library for Processing built with JSyn
https://processing.org/reference/libraries/sound/
GNU Lesser General Public License v2.1
149 stars 50 forks source link

Android mode " no such file or directory" #103

Open Henry-derbug opened 6 months ago

Henry-derbug commented 6 months ago

Running the SimplePlayback example (processing4.2) on an android 13 (and others) phone throws the error:

java.io.FileNotFoundException: /data/user/0/processing.test.simpleplayback/files/null.wav: open failed: ENOENT (No such file or directory)

command that causes the error: soundfile = new SoundFile(this, "null.wav");

the "null.wav" file is located in the data directory of the app.

i also checked absolute path on internal or external storage but the SoundFile Class doesnt accept sparators in the path.

The path that the SoundFile(this, "null.wav"); throws is different from the correct android path.

path from error SoundFile(this, "null.wav"); /data/user/0/processing.test.simpleplayback/files ####### path from
SDcards = context.getExternalFilesDirs(null); sdPath0 = SDcards[0].toString() ; sdPath1 = SDcards[1].toString() ; sdPath0: /storage/emulated/0/Android/data/processing.test.simpleplayback/files

what can I do to get the SoundFile playing the .wav file from internal memory or external SDCard on an android?

kevinstadler commented 6 months ago

Could you try loading the file using its full absolute path? I.e.:

new SoundFile(this, "/storage/emulated/0/Android/data/processing.test.simpleplayback/files/null.wav");
Henry-derbug commented 6 months ago

SoundFile Class doesnt accept sparators in the path.

java.lang.IllegalArgumentException: File /temp.wav contains a path separator

not a single one and not several in the absolute path.

I found out that openFile behaves different in java and in android, One should use streams to open files with separators but this is too sophisticated for me to find out a working code. Im so happy to use processing without deepdiving into android tricks. https://stackoverflow.com/questions/5963535/java-lang-illegalargumentexception-contains-a-path-separator

In the same android app I use output = createWriter(sdPath+logfilename+"_log"+".csv"); to write a log file to an absolute path "sdPath" and this works without rejecting the / slash file separator.