Assets manager in my Android games is able to find 3d models & textures but for some reason fails to find audio files. Here is the exception I’m getting:
java.lang.UnsupportedOperationException: Cannot load audio files from classpath.Place your audio files in Android's assets directory
at java.lang.reflect.Method.invoke(Native Method)
I’m using FileLocator with my assets manager to all the needed assets
and as I said it works with 3d models & textures but not with audio files…
It’s not an option for me to put my audio files in the assets folder since my games & assets are dynamic (generated).
What can be done?
EDIT: I see that the assets manager’s file locator DID find the audio file but inside the NativeVorbisLoader class in the “load” method it would not accept AssetInfoFile but only AndroidAssetInfo so I wonder if the “load” method was the correct one to call… Looks like the “load” method will only work with assets put inside the assets folder. File assets should be loaded with other load method. I think.
So, you are using DesktopAssetManager to load Android Audio ?
I think you can just make sceneMax3d copy the assets (using File io & streams or even cmd commands) generated by the project in general into the asset folder so you can package apk & send to users in future, i mean by making the assets a part of android apk…but dynamically.
As you can see here, this is the android asset folder, i have my jme assetFolder there, i can make a java program to copy/paste any assets into this folder so android.content.res.AssetManager can locate my resources :
When jme initializes assetManager through the LegacyApplication, it does getResources for the current class to locate the asset folder using SystemDelegate & it then passes that to the DesktopAssetManager to locate assets, but if the platform is android then that will use Android.cfg file instead of getResources which will direct it to com.jme3.asset.plugins.AndroidLocator instead of using DesktopAssetManager,
So, i am not sure if calling registerLocator would override initAssetManager() call that LegacyApplication does…
yes! and its working perfectly except audio files for some reason. Models, textures anything is loaded perfectly from the storage but not audio files (OGG types). WAV files has another loader which I think doesn’t have this restriction but I got a crash there which I need to check…
I can think of a solution, but it may be complex & it may not work…
So, create a custom Class of AssetLocater, then inside locate() use activityContext.getExternalFilesDir() it returns File pointing at /shared/0/emulated/ your internal storage dir, to create streams that will point to the asset folder you have inside the internal storage
So generally you will substitute the use of AndroidLocator class…
But there is no problem with locating the OGG file. it is located OK but the asset manager’s FileLocator. the problem is with the NativeVorbisLoader which for some reason doesn’t allow loading files which are not from the assets folder