Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config for automatic output device fetching on gwt #7359

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
8 changes: 4 additions & 4 deletions gdx/src/com/badlogic/gdx/audio/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public interface Sound extends Disposable {
* @return the id of the sound instance if successful, or -1 on failure. */
public long play (float volume);

/** Plays the sound. If the sound is already playing, it will be played again, concurrently.
* Note that (with the exception of the web backend) panning only works for mono sounds, not for stereo sounds!
/** Plays the sound. If the sound is already playing, it will be played again, concurrently. Note that (with the exception of
* the web backend) panning only works for mono sounds, not for stereo sounds!
* @param volume the volume in the range [0,1]
* @param pitch the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0
* @param pan panning in the range -1 (full left) to 1 (full right). 0 is center position.
Expand All @@ -69,8 +69,8 @@ public interface Sound extends Disposable {
public long loop (float volume);

/** Plays the sound, looping. If the sound is already playing, it will be played again, concurrently. You need to stop the
* sound via a call to {@link #stop(long)} using the returned id.
* Note that (with the exception of the web backend) panning only works for mono sounds, not for stereo sounds!
* sound via a call to {@link #stop(long)} using the returned id. Note that (with the exception of the web backend) panning
* only works for mono sounds, not for stereo sounds!
* @param volume the volume in the range [0,1]
* @param pitch the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0
* @param pan panning in the range -1 (full left) to 1 (full right). 0 is center position.
Expand Down