mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 17:04:20 +02:00
switch to HMD preferred audio when mounting the HMD
This commit is contained in:
parent
1e7a69fb90
commit
d5ecb99b16
1 changed files with 66 additions and 4 deletions
|
@ -144,3 +144,65 @@ function menuItemEvent(menuItem) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu.menuItemEvent.connect(menuItemEvent);
|
Menu.menuItemEvent.connect(menuItemEvent);
|
||||||
|
|
||||||
|
// Some HMDs (like Oculus CV1) have a built in audio device. If they
|
||||||
|
// do, then this function will handle switching to that device automatically
|
||||||
|
// when you goActive with the HMD active.
|
||||||
|
var wasHmdMounted = HMD.mounted;
|
||||||
|
var switchedAudioInputToHMD = false;
|
||||||
|
var switchedAudioOutputToHMD = false;
|
||||||
|
var previousSelectedInputAudioDevice = "";
|
||||||
|
var previousSelectedOutputAudioDevice = "";
|
||||||
|
function checkHMDAudio() {
|
||||||
|
// Mounted state is changing... handle switching
|
||||||
|
if (HMD.mounted != wasHmdMounted) {
|
||||||
|
print("HMD mounted changed...");
|
||||||
|
|
||||||
|
// We're putting the HMD on... switch to those devices
|
||||||
|
if (HMD.mounted) {
|
||||||
|
print("NOW mounted...");
|
||||||
|
var hmdPreferredAudioInput = HMD.preferredAudioInput();
|
||||||
|
var hmdPreferredAudioOutput = HMD.preferredAudioOutput();
|
||||||
|
print("hmdPreferredAudioInput:" + hmdPreferredAudioInput);
|
||||||
|
print("hmdPreferredAudioOutput:" + hmdPreferredAudioOutput);
|
||||||
|
|
||||||
|
|
||||||
|
var hmdHasPreferredAudio = (hmdPreferredAudioInput !== "") || (hmdPreferredAudioOutput !== "");
|
||||||
|
if (hmdHasPreferredAudio) {
|
||||||
|
print("HMD has preferred audio!");
|
||||||
|
previousSelectedInputAudioDevice = Settings.getValue(INPUT_DEVICE_SETTING);
|
||||||
|
previousSelectedOutputAudioDevice = Settings.getValue(OUTPUT_DEVICE_SETTING);
|
||||||
|
print("previousSelectedInputAudioDevice:" + previousSelectedInputAudioDevice);
|
||||||
|
print("previousSelectedOutputAudioDevice:" + previousSelectedOutputAudioDevice);
|
||||||
|
if (hmdPreferredAudioInput != previousSelectedInputAudioDevice && hmdPreferredAudioInput !== "") {
|
||||||
|
print("switching to HMD preferred audio input to:" + hmdPreferredAudioInput);
|
||||||
|
switchedAudioInputToHMD = true;
|
||||||
|
menuItemEvent("Use " + hmdPreferredAudioInput + " for Input");
|
||||||
|
}
|
||||||
|
if (hmdPreferredAudioOutput != previousSelectedOutputAudioDevice && hmdPreferredAudioOutput !== "") {
|
||||||
|
print("switching to HMD preferred audio output to:" + hmdPreferredAudioOutput);
|
||||||
|
switchedAudioOutputToHMD = true;
|
||||||
|
menuItemEvent("Use " + hmdPreferredAudioOutput + " for Output");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("HMD NOW un-mounted...");
|
||||||
|
if (switchedAudioInputToHMD) {
|
||||||
|
print("switching back from HMD preferred audio input to:" + previousSelectedInputAudioDevice);
|
||||||
|
menuItemEvent("Use " + previousSelectedInputAudioDevice + " for Input");
|
||||||
|
}
|
||||||
|
if (switchedAudioOutputToHMD) {
|
||||||
|
print("switching back from HMD preferred audio output to:" + previousSelectedOutputAudioDevice);
|
||||||
|
menuItemEvent("Use " + previousSelectedOutputAudioDevice + " for Output");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wasHmdMounted = HMD.mounted;
|
||||||
|
}
|
||||||
|
|
||||||
|
Script.update.connect(checkHMDAudio);
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(function () {
|
||||||
|
Menu.menuItemEvent.disconnect(menuItemEvent);
|
||||||
|
Script.update.disconnect(checkHMDAudio);
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue