GWT use webaudio instead of SoundManager2 lib#5659
Conversation
# Conflicts: # backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtApplication.java # extensions/gdx-controllers/gdx-controllers-gwt/.classpath
# Conflicts: # backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtApplicationConfiguration.java
|
About Eclipse files modifications, i checked with my Eclipse configuration (i only have GDT Google Dev. Tools) and eclipse doesn't complain about your changes, i think it's safe to keep it. It could be useful for people using these other plugins. |
|
First of all, thank you to bring this up! I made a few tests with your PR using libgdx tests. AudioContext is created too early and print this warning : Even though it's just a warning, there is some issue cases. My test case was to just play a sound or a music when clicking on any test launcher button (first user interaction).
Music issue can be fixed either :
I quickly test by resuming audio context just before playing the empty sound here and it worked. I'm not sure if it's possible to get rid of this warning. Some people are always afraid about simple warnings (eg Gradle compile 🙄 ). For now, I think it's safe to just resume audio context after first user interaction. |
|
First of all, thank you @MrStahlfelge and @mgsx-dev for reviving this, I had all but given up on it :) In my opinion, the warnings associated with attempting to start playback before a user interaction, is not really feasible to solve from our end. The developer needs to be aware of this, much in the same way as they have to request the right permissions to use hardware features, if they do mobile development. Furthermore, there are many cases where the request for user interaction is not required - eg. if you wrap your HTML5 game using Cordova, Electron or if you support "Add to home screen". I am not sure, but maybe the Chrome developers are coming to our rescue here?
|
|
Hi @barkholt , thanks for engaging here and for the good work. I can understand that you were demotivated. Perhaps you want to join the libGDX discord server linked on the main page, makes the discussion easier. :) At the moment, we are still trying to improve on the autoplay problem. When testing, I discovered that your original solution had the problem that, when the context gets unlocked, it plays all sounds at once that were tried to play so far. I changed that with 073a953, but this commit will also suppress playback if audio is not locked at all. EDIT: solved by 7e661eb |
fix autoPlay for musics
fix obtain graph from pool instead of create a new one
removed unused constructor
revert line ending changes for readability in history
avoid implicit int to float conversion for consistency
fix music completion listener
fix documentation
…first interaction otherwise
| this.audioContext = audioContext; | ||
| this.destinationNode = destinationNode; | ||
|
|
||
| setupAudoGraph(); |
| @Override | ||
| public void pause () { | ||
| // As the web application looses focus, we mute the sound | ||
| disconnectJSNI(); |
There was a problem hiding this comment.
Would it be possible to change this dynamically?
I.e. allow to not mute on focus loss?
|
|
||
| public void ended() | ||
| { | ||
| if(this.onCompletionListener != null) this.onCompletionListener.onCompletion(this); |
|
|
||
| @Override | ||
| public void setOnCompletionListener (OnCompletionListener listener) { | ||
| this.onCompletionListener = listener; |
| audioBufferSourceNode.loop = looping; | ||
| }-*/; | ||
|
|
||
| public static native boolean getLoopingJSNI (JavaScriptObject audioBufferSourceNode) /*-{ |
There was a problem hiding this comment.
Maybe rename to isLoopingJSNI?
| }-*/; | ||
|
|
||
| public static native float getResumeOffsetJSNI (JavaScriptObject audioBufferSourceNode) /*-{ | ||
| return audioBufferSourceNode.pauseTime |
There was a problem hiding this comment.
Is this formatting intended?
|
Nice work @barkholt @MrStahlfelge @mgsx-dev . if(foo)
bar()
else
bart()
vs.
if(foo) {
bar()
} else {
bart()
} |
|
Just wanted to say Thanks to @MrStahlfelge for your work on this and keeping it alive. The sound issues in my HTML5 projects were causing major headaches on Mobile platforms with the inability to have more than one Music or Sound playing simultaneously. Every time a sound was played it would cause the previously playing sound to stop. The only thing I would like to point out is that, if this were to ever get merged. In HtmlLauncher.java, the re-size code that's commented out has this line "cfg.preferFlash = false;" |
|
This PR would probably be a good candidate to be added as an alternative implementation after #6017 was merged. |
|
@crykn I don't see this as an alternative implementation for SoundManager because SoundManager just does not work as intended any more. There's no thing in keeping it, and that's the reason why I won't publish this as an add-on or so. That said, I don't understand why this didn't get merged. |
# Conflicts: # backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtApplication.java # backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtAudio.java # backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/soundmanager2/SoundManager.java # extensions/gdx-setup/res/com/badlogic/gdx/setup/resources/html/war/soundmanager2-jsmin.js # extensions/gdx-setup/res/com/badlogic/gdx/setup/resources/html/war/soundmanager2-setup.js
tommyettinger
left a comment
There was a problem hiding this comment.
This has been in use by projects that use MrStahlfelge/gdx-backends for a long time, and it seems quite stable. With Flash essentially unusable either now or very soon, an alternative is needed, and this seems like
a very good one.
|
It is done. Thank you for the efforts and patience to all contributors in this case. To preserve the original author information, I did not sqash the merge this time. |
New PR for WebAudio implementation by @barkholt (original PR was #4220).
I picked the important commits of this PR and merged it against the latest libgdx versions. After testing, I can safely say that this is better than SoundManager2.
Some advantages I found so far:
Caveats I found so far:
Live example to try
Tested so far on
For those wanting to try or to use this in existing 1.9.8/1.9.9/1.9.10 games: you can find Jitpack dependencies to use with libGDX 1.9.8 (working with 1.9.9, too), 1.9.10 and 1.9.11 here.
About the changes on the Eclipse files: I don't know if they are needed because I don't use Eclipse. If needed, I can revert the changes to .project/.classpath files.
Changes.md:
I did not update changes.md so far because I am not sure if this will get merged (soon) and are afraid of merge conflicts. The following should be added there when this gets merged.
* HTML: changed audio backend to WebAudio API. Now working on mobiles, pitch implemented. Configuration change: preferFlash removed. When updating existing projects, you can remove the soundmanager js files from your webapp folder and the references to it from the index.html