We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone,
Thanks for taking the time to read this. I'm using Android Studio to package my processing sketches as outlined here.
I have a basic test sketch working fine which simply draws ellipses on screen. However, I'm having issues loading images and other media files, usually they would go into the data folder (I'm more used to p5.js in which case I put them into an assets folder and load them using relative URLs).
Where do I need to put images/mp3s within my android project so that I can load them using PImage and loadImage with processing?
If anyone can help I would greatly appreciate it.
Thanks,
Matt
Answers
This link will provide you some options as describe to Android developers:https://developer.android.com/guide/topics/data/data-storage.html
Also in the next link check the getAssets function: https://forum.processing.org/two/discussion/comment/85705/#Comment_85705
You can also use external storage: https://forum.processing.org/two/discussion/18126/load-image-files-from-external-storage-to-pimage/p1
https://forum.processing.org/two/discussion/21167/accessing-sd-cards-for-storage#latest
If you decide to go for this option, don't forget to enable sketch permission to write in the external storage.
I am curious if dataPath("") an sketchFolder(); would work in AS. Maybe give it a try. Those functions are not documented in the reference but you can see them in action in these posts:
https://forum.processing.org/two/discussion/11162/sketchpath-is-not-visible-3-0a9
https://forum.processing.org/two/discussion/comment/61200/#Comment_61200
https://forum.processing.org/two/search?Search=dataPath
Kf
Thanks Kf for taking the time to answer.
I won't be able to test it for a couple of days because of other commitments but I'll give it a try.The dataPath and sketchFolder functions sound ideal if they work.I'll give it a test when I can and report back :)So, I haven't tested loading images yet but I can report that sketchPath returns:
/data/user/0/com.android.test/files
Also dataPath("test.png") returns:
/data/user/0/com.android.test/files/data/test.png
This is all through the android emulator.
Now I just need to figure out how store and access the files in the correct place, more testing needed :)
I was kind of hoping it would be as easy as creating a data folder somewhere in the android project, dropping the images/mp3s into it then using loadImage etc as you would in processing, but I can see this isn't the case.
The getAssets function you linked to also looks like it might work but I'll have to unpick what's going on in that example, I'm still very new to android development and this is the first time I've tried Processing (I've been doing everything in p5.js).
Cheers
Matt
The following works fine for me in windows:
String pathToSketch = Base.getSketchbookFolder().getAbsolutePath();
Try it. It is worth investigating the data provided by parent Processing framework through this Base parameter.
Base is not documented, or is it? I will prefer to stick to the other undocumented functions: dataPath() or sketchPath() as I believe that is what they are meant for. However, I am not sure how these calls will behave outside Processing. The only thing I can say is that It should work...
Kf
Thanks both, for the time being I'm sticking with the simpler option of developing my app in p5.js and having the android app present a full screen webview to then load the sketch from Googles App Engine (are there any issues with this other than requiring internet access?).
However, that said I have managed to create a simple sketch within processing, export it as an android project and then load and compile this within Android Studio including using loadImage to load an image. I'm not sure what clever things processing is doing when exporting the library that I found difficult, however this definitely seems like an alternative and will eventually get me around the issue.
@Matt_CodePlayground This gives from Eclipse same result as sketchPath from the processing editor:
processing.app.ui.Editor editor = base.getActiveEditor(); System.out.println("samme as getsketchPath: " + editor.getSketch().getMainFilePath());
I obtain information over these classes from the automatic text completion existing in Eclipse. There you can write "base" or "editor" or the matter you search information for and then pressing Ctrl+Space an emerging window shows you the different uses for the classes. If you put a dot after the reserved word, the different options are shown. I hope this helps. Greetings.
@vesolba
Thanks for your explanation.
Kf