Search code examples
gwtlibgdxgame-development

Why LibGDX sound pitch doesn't work with GWT?


I use the instance of class Sound. To get the desired pitch I use the method:

public long loop (float volume, float pitch, float pan);

It works as expected on desktop build but on GWT pitch isn't working.

My gwtVersion is 2.8.2, gdxVersion is 1.9.10 and I use de.richsource.gradle.plugins:gwt-gradle-plugin:0.6.

I have been stuck on this problem for a couple of days now and would be very thankful for any input.


Solution

  • "Why LibGDX sound pitch doesn't work with GWT?"

    Because the official libGDX GWT backend uses SoundManager for playing sounds within the browser, and SoundManager does not support pitching.

    To get it run, you must change to another solution: the WebAudio API. Lucky as you are, others already implemented it for libGDX, but it is not pulled into the repository for unknown reasons. See PR 5659.

    As told in the PR, you can switch to my forked GWT backend to get it to work. Simply change your gradle.build file

    implementation 'com.github.MrStahlfelge.gdx-backends:gdx-backend-gwt:1.910.0'
    

    You also need to declare the Jitpack repo if you don't already have.