Closed Ali-RS closed 1 year ago
Should probably be resolved after switching to OGGLoader https://github.com/jMonkeyEngine/jmonkeyengine/pull/1961
This is forced by the android architecture, android doesn't use regular .class
and METAINF
that adds some files to the classpath, the classpath of android is different and i don't know the underlying architecture as i still have some issues with the android classpath incompatibilities with regular java, but this is a user problem anyway, you should load the assets from the asset folder which is added to the application path and shipped with the apk.
EDIT:
.class
files into 1 to 2 .dex
files (it depends on the multidex
flag).MyClass.class.getResources(String)
will return null.jme-test
api which is currently drafted.but this is a user problem anyway
Note that the author of the forum topic linked above mentioned that it works fine with textures (I guess texture also uses a native loader on android), wav audio, and models... the issue happens only with NativeVorbisLoader, so it sounds like a bug to me.
Going to try this myself
Android has its own AssetLocator that i think redirects everything to the asset folder even outside directories; because Class.getResources(String)
is null....
I need to take a closer look but from a quick glance, the main difference is that other loaders directly load from InputStream using JME AssetInfo.openStream()
but NativeVorbisLoader
depends on AndroidAssetInfo and AssetFileDescriptor.
For example, see AndroidNativeImageLoader
or OGGLoader
but NativeVorbisLoader works differently:
The NativeVorbisLoader needs a low level file descriptor for the native side code forced by the Ogg library from xiph.org and it doesn't need a direct stream...
@Scrappers-glitch does NativeVorbisLoader work if I put Ogg files in the assets.jar
(like the regular JME desktop app) when building for android?
If the asset.jar
is added on the android lib folder and implemented as a jar from build.gradle then, yes the android apk can read them, but as for the NativeVorbisLoader, you may consider testing this; because the code may have other underlying problems we don't know unless spotted on a bug report.
EDIT: You have to give the right relative path when initializing an audio node, the same as the desktop one.
Btw, for more information, i suggest using the apk-analyzer tool shipped with the android-studio, it will help you a lot to locate files loaded into the application compression.
does NativeVorbisLoader work if I put Ogg files in the assets.jar (like the regular JME desktop app) when building for android?
I tried this and it does not work with ogg. I got the same error java.lang.UnsupportedOperationException: Cannot load audio files from classpath.Place your audio files in Android's assets directory
. It works fine with WAV files.
Also, it works fine if I use OGGLoader (from jme3-jogg) instead of NativeVorbisLoader.
Resolved by #1961
Android NativeVorbisLoader can not load audio files outside Android's assets directory.
https://github.com/jMonkeyEngine/jmonkeyengine/blob/0cb5fe755582d776ddf223ce88771d958f4818cf/jme3-android/src/main/java/com/jme3/audio/plugins/NativeVorbisLoader.java#L151-L158
Related forum posts:
https://hub.jmonkeyengine.org/t/solved-cannot-load-audio-files-from-classpath-place-your-audio-files-in-androids-assets-directory/37050
https://hub.jmonkeyengine.org/t/android-assets-manager-cannot-find-audio-files/44638