Skip to content

Commit

Permalink
Add config for automatic output device fetching on gwt
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonIT committed Mar 6, 2024
1 parent 7c9a542 commit 84be107
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Expand Up @@ -16,6 +16,7 @@

package com.badlogic.gdx.backends.gwt;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.AudioDevice;
import com.badlogic.gdx.audio.AudioRecorder;
import com.badlogic.gdx.audio.Music;
Expand All @@ -35,22 +36,24 @@ public class DefaultGwtAudio implements GwtAudio {
public DefaultGwtAudio () {
webAudioAPIManager = new WebAudioAPIManager();

getUserMedia();
Timer observer = new Timer() {
@Override
public void run () {
fetchAvailableOutputDevices(new DeviceListener() {
@Override
public void onDevicesChanged (String[] ids, String[] labels) {
outputDeviceLabelsIds.clear();
for (int i = 0; i < ids.length; i++) {
outputDeviceLabelsIds.put(labels[i], ids[i]);
if (((GwtApplication)Gdx.app).config.fetchAvailableOutputDevices) {
getUserMedia();
Timer observer = new Timer() {
@Override
public void run () {
fetchAvailableOutputDevices(new DeviceListener() {
@Override
public void onDevicesChanged (String[] ids, String[] labels) {
outputDeviceLabelsIds.clear();
for (int i = 0; i < ids.length; i++) {
outputDeviceLabelsIds.put(labels[i], ids[i]);
}
}
}
});
}
};
observer.scheduleRepeating(1000);
});
}
};
observer.scheduleRepeating(1000);
}
}

@Override
Expand Down
Expand Up @@ -76,6 +76,9 @@ public class GwtApplicationConfiguration {
/** whether to make the webgl context compatible with WebXR, may have positive performance impact **/
public boolean xrCompatible = false;

/** Whether to fetch available output devices. It asks the user automatically for permission */
public boolean fetchAvailableOutputDevices = false;

/** Creates configuration for a resizable application, using available browser window space minus padding (see
* {@link #padVertical}, {@link #padHorizontal}). */
public GwtApplicationConfiguration () {
Expand Down

0 comments on commit 84be107

Please sign in to comment.