How to disable audio for SimpleApplication

I just started the tutorial but unfortunately I can’t get past the “Could not locate OpenAL library.” exception for the Hello SimpleApplication because my computer does not have a sound card (work doesn’t allow sound cards).

Is there any way around that?

http://javadoc.jmonkeyengine.org/com/jme3/system/AppSettings.html#setAudioRenderer-java.lang.String-

2 Likes

I had this problem too. I disable my soundcard and use HDMI or bluetooth. If I have no sound it results in the same output as above. I never bothered to look into why. Tyvm.

I am still getting the same exception :frowning:

public class MyGame extends SimpleApplication {

    public static void main(String[] args){
    	AppSettings settings = new AppSettings(true);
    	settings.setAudioRenderer(null);
    	
    	MyGame app = new MyGame();
    	app.setSettings(settings);
        app.start(); // start the game
 
    }

    @Override
    public void simpleInitApp() {
        Box b = new Box(1, 1, 1); // create cube shape
        Geometry geom = new Geometry("Box", b);  // create cube geometry from the shape
        Material mat = new Material(assetManager,
          "Common/MatDefs/Misc/Unshaded.j3md");  // create a simple material
        mat.setColor("Color", ColorRGBA.Blue);   // set color of material to blue
        geom.setMaterial(mat);                   // set the cube's material
        rootNode.attachChild(geom);              // make the cube appear in the scene
    }
}
AL lib: (EE) MMDevApiOpenPlayback: Device init failed: 0x80070490
AL lib: (EE) MMDevApiOpenPlayback: Device init failed: 0x80070490
AL lib: (EE) MMDevApiOpenPlayback: Device init failed: 0x80070490
AL lib: (EE) MMDevApiOpenPlayback: Device init failed: 0x80070490
Sep 14, 2017 11:18:23 AM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.RuntimeException: org.lwjgl.LWJGLException: Could not locate OpenAL library.
	at com.jme3.audio.lwjgl.LwjglALC.createALC(LwjglALC.java:17)
	at com.jme3.audio.openal.ALAudioRenderer.initOpenAL(ALAudioRenderer.java:95)
	at com.jme3.audio.openal.ALAudioRenderer.initialize(ALAudioRenderer.java:225)
	at com.jme3.app.LegacyApplication.initAudio(LegacyApplication.java:283)
	at com.jme3.app.LegacyApplication.initialize(LegacyApplication.java:603)
	at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:178)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:211)
	at java.lang.Thread.run(Unknown Source)

Then you need to rebuild again or something because that code must not be being used.

If you look at the initAudio() code:

 private void initAudio(){
        if (settings.getAudioRenderer() != null && context.getType() != Type.Headless){
            audioRenderer = JmeSystem.newAudioRenderer(settings);
            audioRenderer.initialize();  // Line 283 from the exception
            AudioContext.setAudioRenderer(audioRenderer);

            listener = new Listener();
            audioRenderer.setListener(listener);
        }
}

There is no way that block runs if the audio renderer is null.

And there is nothing special about AppSettings as it’s just a map. So… not sure what to tell you.

Edit: updated with the exception line number to prove that app settings is not setup right in that error dump.

And it actually sounds like lwjgl is unable to load the openAL.dll it extracts. Maybe you’d have the same problem for physics then.

Do you have some restriction/anti Virus blocking dlls?

Anyway try a Clean & Build, Maybe something just got messed up

I edited your post. Look how beautiful it looks when you use code blocks :slight_smile:

2 Likes

Seems I’m a late poster in this thread, but I stumbled onto the same issue myself. I did some research, and I believe I may have found a bug in how the AppSettings’ AudioRenderer value is handled.

I’ve based my application on the SimpleApplication class, and I got the same “Could not locate OpenAL library” message while using a computer without a sound card driver. After reading this thread, I tried OP’s approach by creating my own AppSettings and setting its AudoRenderer value to null:

public static void main(String[] args){
    AppSettings settings = new AppSettings(true);
    settings.setAudioRenderer(null);

    MyGame app = new MyGame();
    app.setSettings(settings);
    app.start();
}

As OP, I still got the same result as before. The code inside the initAudio() method mentioned by pspeed would still run, causing exceptions.

After a little debugging, I noticed that AudoRenderer’s value in AppSettings had reverted back to “LWJGL” and was no longer null when initAudio() was invoked. This was a bit strange, since I was sure I set it to null in the main() method. A bit more research, and I noticed that the AudioRenderer value got changed back to “LWJGL” when SimpleApplication.start() was invoked.

I checked the JME documentation to make sure I wasn’t using AppSettings in an unintentional way, but according to the information found at https://jmonkeyengine.github.io/wiki/jme3/intermediate/appsettings.html, OP’s approach is correct, and I assume this is how it’s intended to work.

This seems to be an issue exclusively with the AudioRenderer. I haven’t tested all settings, but the FrameRate setting, for instance, doesn’t get overwritten, and works just fine. I was able to work around the issue by setting the AudioRenderer to null on both the SimpleApplication and its context after invoking app.start(), but this feels like a hack.

I’m running JME version 3.2-stable on 64-bit linux.

2 Likes

I like using my computer speakers to play my music stored on my old, unusable except through the internet connection at my house, smart phone(stupid phone now) and found this same thing happens on win 7.

This requires unplugging the external pc speakers and plugging them into my phones headphone jack, thereby disabling sound on the pc.

The serenic fix does work but it sure feels strange setting things like this. In my case I only set it with context since using AppSettings has no effect.

        main.start();
        //Disable when jamming to the music.
        main.getContext().getSettings().setAudioRenderer(null);

Feels dirty, am I supposed to do this differently?

The fact that setting the audio renderer to null doesn’t work is likely due to code like this:

…that incorrectly assumes that ‘null’ means ‘not set’ instead of checking for the key.

so something like?

        if (get(key) == null && other.get(key) != null) {
            put(key, other.get(key));
        }

No.

if( !hasKey(key) )

…the other value doesn’t have null in it or this wouldn’t be an issue.

public void mergeFrom(AppSettings other) {
    for (String key : other.keySet()) {
        if( !hasKey(key) ) {
            put(key, other.get(key));
        }
    }
}

Yeah, I mean I can’t promise that’s the issue here but it’s probably something like that… it could be that.

It was just a bug I noticed when skimming the code because I had a hunch.

ok, ill try it first.

This did work.

    public void mergeFrom(AppSettings other) {
        for (String key : other.keySet()) {
            if( !this.containsKey(key) ) {
                put(key, other.get(key));
            }
        }
    }

I tested it by setting these two settings since they were the only ones that I saw that take a null parameter.

        settings.setRenderer(null);
        settings.setAudioRenderer(null);

Without the change to AppSettings, setting setRenderer(null); had no effect, the app would startup, the settings dialog runs, game loads normally.

With the change, the app just sits there running, no settings dialog shows so can go no further.

Without the change to AppSettings, setAudioRenderer(null);, the setting is ignored and causes an exception, app crashes.

With the change, the setting is recognized, the settings dialog runs. game loads normally.

I ran TestCustomAppSettings and it shows as ok but not sure that means anything. is there a more robust way to test this other than these two settings?

1 Like

Seems like enough testing. The code was already suspect.

As a team lead in my day job, I automatically learn to spot things like this… or automatically suspect them when certain symptoms arise.

Which is another way of saying, it was already a bug/bad-smell… so fixing it is a good idea. The fact that it also fixes the real problem you were seeing only makes it even better. (JME codebase is pretty good overall but there are plenty of these little off-smell things all over the place to those with a sensitive nose.)

Yeah, you spotted that quick. That’s one of those pitfall bugs that takes experience to catch.

I will do a pr and refer back to here.

1 Like

Thank you guys for resolving this issue. Me and probably a lot more people already had some problems with this “AL-Library not found”-problem.

Glad to hear that this has been eradicated :slight_smile:

Its not eradicated, the way to avoid the problem has been improved. Defensive coding at its best.

In a dream world, not having a sound card or disabled sound would just be ignored.