Audio on Android - Looping

About the “Interface/Sounds/mysound.ogg” path I wanted to say “Sounds/mysound.ogg”. This is a symptom for a nifty user :P.

Ok, here is what DDMS says:

Code:
12-21 13:22:08.257: E/AndroidHarness(4131): java.lang.IllegalStateException: No loader registered for type "wav" 12-21 13:22:08.267: E/AndroidHarness(4131): SEVERE AndroidHarness 13:22:08 Exception thrown in Thread[GLThread 10,5,main]: at com.jme3.asset.DesktopAssetManager.loadAsset(248) 12-21 13:22:08.267: E/AndroidHarness(4131): at com.jme3.audio.AudioNode.<init>(182) 12-21 13:22:08.267: E/AndroidHarness(4131): at com.jme3.audio.AudioNode.<init>(209) 12-21 13:22:08.267: E/AndroidHarness(4131): at mygame.AudioManager.<init>(24) 12-21 13:22:08.267: E/AndroidHarness(4131): at mygame.Main.simpleInitApp(49) 12-21 13:22:08.267: E/AndroidHarness(4131): at com.jme3.app.SimpleApplication.initialize(231) 12-21 13:22:08.267: E/AndroidHarness(4131): at com.jme3.system.android.OGLESContext.initInThread(266) 12-21 13:22:08.267: E/AndroidHarness(4131): at com.jme3.system.android.OGLESContext.onSurfaceCreated(217) 12-21 13:22:08.267: E/AndroidHarness(4131): at android.opengl.GLSurfaceView$GLThread.guardedRun(1322) 12-21 13:22:08.267: E/AndroidHarness(4131): at android.opengl.GLSurfaceView$GLThread.run(1121)

Btw it looks .wav are not registered by AndroidAssetManager.java, btw .ogg and .wav are.



[java]

/**

  • AndroidAssetManager constructor
  • If URL == null then a default list of locators and loaders for android is set
  • @param configFile

    */

    public AndroidAssetManager(URL configFile) {



    System.setProperty("org.xml.sax.driver", "org.xmlpull.v1.sax2.Driver");





    // Set Default Android config

    this.registerLocator("", AndroidLocator.class);

    this.registerLocator("", ClasspathLocator.class);

    this.registerLoader(AndroidImageLoader.class, "jpg", "bmp", "gif", "png", "jpeg");

    this.registerLoader(AndroidAudioLoader.class, "ogg", "mp3");

    this.registerLoader(com.jme3.material.plugins.J3MLoader.class, "j3m");

    this.registerLoader(com.jme3.material.plugins.J3MLoader.class, "j3md");

    this.registerLoader(com.jme3.font.plugins.BitmapFontLoader.class, "fnt");

    this.registerLoader(com.jme3.texture.plugins.DDSLoader.class, "dds");

    this.registerLoader(com.jme3.texture.plugins.PFMLoader.class, "pfm");

    this.registerLoader(com.jme3.texture.plugins.HDRLoader.class, "hdr");

    this.registerLoader(com.jme3.texture.plugins.TGALoader.class, "tga");

    this.registerLoader(com.jme3.export.binary.BinaryImporter.class, "j3o");

    this.registerLoader(com.jme3.scene.plugins.OBJLoader.class, "obj");

    this.registerLoader(com.jme3.scene.plugins.MTLLoader.class, "mtl");

    this.registerLoader(com.jme3.scene.plugins.ogre.MeshLoader.class, "meshxml", "mesh.xml");

    this.registerLoader(com.jme3.scene.plugins.ogre.SkeletonLoader.class, "skeletonxml", "skeleton.xml");

    this.registerLoader(com.jme3.scene.plugins.ogre.MaterialLoader.class, "material");

    this.registerLoader(com.jme3.scene.plugins.ogre.SceneLoader.class, "scene");

    this.registerLoader(com.jme3.shader.plugins.GLSLLoader.class, "vert", "frag", "glsl", "glsllib");





    logger.info("AndroidAssetManager created.");

    }

    [/java]

I’m not sure if I get what you said but i tried to register the loader for ogg and wav:

Code:
app.getAssetManager().registerLoader(AndroidAudioLoader.class, "ogg", "wav");
And I received:
Code:
12-21 19:59:14.568: E/AndroidAudioRenderer(5974): java.io.FileNotFoundException: Sounds/gun1.wav 12-21 19:59:14.568: E/AndroidAudioRenderer(5974): at android.content.res.AssetManager.openAssetFd(Native Method) 12-21 19:59:14.568: E/AndroidAudioRenderer(5974): at android.content.res.AssetManager.openFd(AssetManager.java:329) 12-21 19:59:14.568: E/AndroidAudioRenderer(5974): at com.jme3.audio.android.AndroidAudioRenderer.playSourceInstance(AndroidAudioRenderer.java:417) 12-21 19:59:14.568: E/AndroidAudioRenderer(5974): at com.jme3.audio.AudioNode.playInstance(AudioNode.java:256) 12-21 19:59:14.568: E/AndroidAudioRenderer(5974): at mygame.AudioManager.playShootSound(AudioManager.java:38) 12-21 19:59:14.568: E/AndroidAudioRenderer(5974): at mygame.Main$1.onAction(Main.java:73)

Still looks like there was no such file in my assets but there is! What is wrong?
btw .ogg and .wav are.


Ops, I wanted to say .ogg and .mp3 accordling to AndroidAssetManager.java:

[java]
this.registerLoader(AndroidAudioLoader.class, "ogg", "mp3");
[/java]

btw mp3 is not supported by desktop asset manager, but it's for the android one. But it should work for mp3 and ogg. Can you check if that constructor is being called by default by android asset manager instead of the deprecated one? The output will show something like:

[java]
21/12/2011 16:39:25 com.jme3.asset.AndroidAssetManager AndroidAssetManager
AndroidAssetManager created.
[/java]

Forget what I said, because you said taht it’s just not working for sounds. Then there’s something weird.

I register that loader in the assetManager from simpleApplication passed to my audiomanager. To make sure that It will be androidAssetManager (not the desktop one) I changed:

Code:
assetManager = JmeSystem.newAssetManager(null);

in simpleInitApp() to:
Code:
assetManager = new AndroidAssetManager();

But still I receive that weird exceprion only for loading sounds :( That just makes me really mad.... :(

Hmmm. Why are you using the SimpleApplication one? Shouldn’t it be the AndroidApplication one? Btw the initialize method of the AndroidApplication class initializes the assetManager with a DesktopAssetManager instance, then override that and use JmeAndroidSystem instead. I never deployed for android before in jme, then I might be wrong :P. I’ve just checked the source code.

But loading other assets like objects or textures works and I use the same assetManager for that. Only loading sounds doesn’t work :frowning:

I’m curious how you’re loading your sounds.

Like this:

Code:
public AudioManager(SimpleApplication app) { this.app = app; app.getAssetManager().registerLoader(AndroidAudioLoader.class, "ogg", "mp3"); gun = new AudioNode(app.getAssetManager(), "Sounds/gun1.mp3", false); gun.setLooping(false); gun.setVolume(2); app.getRootNode().attachChild(gun); }

Makes no difference if this is mp3 or ogg or wav. The error is always the same as I posted few posts before…

As normen said, before, it might be a decoding issue. You are passing “false” in “stream” parameter in AudioNode constructor. That constructor calls another constructor, and pass “false” for the “streamCache” of the another constructor, it means it will decode the sound if it’s false. Try using “true” for the “streamCache” and “stream” params to avoid decoding. Just read the doc :



[java]

/**

  • Creates a new <code>AudioNode</code> with the given audio file.

    *
  • @param assetManager The asset manager to use to load the audio file
  • @param name The filename of the audio file
  • @param stream If true, the audio will be streamed gradually from disk,
  •           otherwise, it will be buffered.<br />
    
  • @param streamCache If stream is also true, then this specifies if
  • the stream cache is used. When enabled, the audio stream will
  • be read entirely but not decoded, allowing features such as
  • seeking, looping and determining duration.

    */

    public AudioNode(AssetManager assetManager, String name, boolean stream, boolean streamCache) {

    this.audioKey = new AudioKey(name, stream, streamCache);

    this.data = (AudioData) assetManager.loadAsset(audioKey);

    }

    [/java]

So I set those both flags to true and on my android device I don’t see any errors but DDMS still shows:

Code:
12-22 01:44:27.243: E/AndroidAudioRenderer(11666): SEVERE AndroidAudioRenderer 01:44:27 Failed to play Sounds/gun1.mp3 12-22 01:44:27.243: E/AndroidAudioRenderer(11666): java.io.FileNotFoundException: Sounds/gun1.mp3 12-22 01:44:27.243: E/AndroidAudioRenderer(11666): at android.content.res.AssetManager.openAssetFd(Native Method) 12-22 01:44:27.243: E/AndroidAudioRenderer(11666): at android.content.res.AssetManager.openFd(AssetManager.java:329) 12-22 01:44:27.243: E/AndroidAudioRenderer(11666): at com.jme3.audio.android.AndroidAudioRenderer.playSourceInstance(AndroidAudioRenderer.java:384) 12-22 01:44:27.243: E/AndroidAudioRenderer(11666): at com.jme3.audio.AudioNode.playInstance(AudioNode.java:256) 12-22 01:44:27.243: E/AndroidAudioRenderer(11666): at mygame.AudioManager.playShootSound(AudioManager.java:38) 12-22 01:44:27.243: E/AndroidAudioRenderer(11666): at mygame.Main$1.onAction(Main.java:74)

@larynx?

I may be off-topic but:



according to:



http://remwebdevelopment.com/dev/a63/Playing-Audio-error-PVMFErrNotSupported-Prepare-failed-status0x1-.html

http://code.google.com/p/libgdx/issues/detail?id=510



this seems to be a bug on samsung phones.





replacing:

[java]AssetFileDescriptor afd = am.openFd(assetKey.getName());

mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());[/java]



by



[java]FileInputStream fis = new FileInputStream(assetKey.getName());

mp.setDataSource(fis.getFD());[/java]



in AndroidAudioRenderer

does the trick.

1 Like

Also getting this issue on device Samsung GS2 IG9100.



FileNotFound issue for audio. Other assets are working as expected.

are your audio assets in the android asset folder?

I am using eclipse and have assets:



Graphics/Textures/dirt.jpeg

Sounds/Effects/lightning.ogg

Sounds/Effects/lightning.mp3



Working 100% on netbeans on PC.



Doing Android dev on Eclipse, exact same src files from Netbeans but with AndroidHarness.



Have tried:



/ being project root

/assets/assets.zip (FileNotFound)

/libs/assets.jar (Textures loading correctly from here, Audio loading fails to “load”)





Btw JME ftw! I like it!



it says:







SEVERE AndroidAudioRenderer … Failed to load sound “Sounds/Effects/lightning.ogg”

java.io.FileNotFoundException: Sounds/Effects/lightning.ogg



04-03 11:30:03.369: E/AndroidAudioRenderer(29778): SEVERE AndroidAudioRenderer 11:30:03 AM Failed to load sound Sounds/Effects/lightning05.ogg

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): java.io.FileNotFoundException: Sounds/Effects/lightning05.ogg

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at android.content.res.AssetManager.openAssetFd(Native Method)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at android.content.res.AssetManager.openFd(AssetManager.java:333)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at com.jme3.audio.android.AndroidAudioRenderer.playSourceInstance(AndroidAudioRenderer.java:333)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at com.jme3.audio.AudioNode.playInstance(AudioNode.java:256)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at my.package.graphics.GameView.playRandomBoltSound(GameView.java:557)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at my.package.graphics.GameView.lightningBoltEffect(GameView.java:539)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at my.package.graphics.GameView.onAction(GameView.java:477)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at com.jme3.input.InputManager.invokeActions(InputManager.java:168)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at com.jme3.input.InputManager.onMouseButtonEventQueued(InputManager.java:403)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at com.jme3.input.InputManager.processQueue(InputManager.java:801)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at com.jme3.input.InputManager.update(InputManager.java:851)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at com.jme3.app.Application.update(Application.java:605)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at com.jme3.app.SimpleApplication.update(SimpleApplication.java:233)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at com.jme3.app.AndroidHarness.update(AndroidHarness.java:430)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:367)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1388)

04-03 11:30:03.369: E/AndroidAudioRenderer(29778): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1138)

mhhh make sure that the generated apk has an assets/Sounds/Effects/lightning.ogg file