mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 05:52:38 +02:00
update JS with Audio.muted
This commit is contained in:
parent
79563b7d83
commit
337b6bca14
7 changed files with 16 additions and 232 deletions
|
@ -25,7 +25,6 @@ var DEFAULT_SCRIPTS_COMBINED = [
|
|||
"system/tablet-goto.js",
|
||||
"system/marketplaces/marketplaces.js",
|
||||
"system/edit.js",
|
||||
"system/selectAudioDevice.js",
|
||||
"system/notifications.js",
|
||||
"system/dialTone.js",
|
||||
"system/firstPersonHMD.js",
|
||||
|
|
|
@ -27,7 +27,7 @@ var UNMUTE_ICONS = {
|
|||
};
|
||||
|
||||
function onMuteToggled() {
|
||||
if (AudioDevice.getMuted()) {
|
||||
if (Audio.muted) {
|
||||
button.editProperties(MUTE_ICONS);
|
||||
} else {
|
||||
button.editProperties(UNMUTE_ICONS);
|
||||
|
@ -46,7 +46,7 @@ function onClicked() {
|
|||
Entities.editEntity(entity, { textures: JSON.stringify({ "tex.close": HOME_BUTTON_TEXTURE }) });
|
||||
shouldActivateButton = true;
|
||||
shouldActivateButton = true;
|
||||
tablet.loadQMLSource("../audio/Audio.qml");
|
||||
tablet.loadQMLSource("../dialogs/Audio.qml");
|
||||
onAudioScreen = true;
|
||||
}
|
||||
}
|
||||
|
@ -60,8 +60,8 @@ function onScreenChanged(type, url) {
|
|||
|
||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||
var button = tablet.addButton({
|
||||
icon: AudioDevice.getMuted() ? MUTE_ICONS.icon : UNMUTE_ICONS.icon,
|
||||
activeIcon: AudioDevice.getMuted() ? MUTE_ICONS.activeIcon : UNMUTE_ICONS.activeIcon,
|
||||
icon: Audio.muted ? MUTE_ICONS.icon : UNMUTE_ICONS.icon,
|
||||
activeIcon: Audio.muted ? MUTE_ICONS.activeIcon : UNMUTE_ICONS.activeIcon,
|
||||
text: TABLET_BUTTON_NAME,
|
||||
sortOrder: 1
|
||||
});
|
||||
|
@ -70,7 +70,7 @@ onMuteToggled();
|
|||
|
||||
button.clicked.connect(onClicked);
|
||||
tablet.screenChanged.connect(onScreenChanged);
|
||||
AudioDevice.muteToggled.connect(onMuteToggled);
|
||||
Audio.mutedChanged.connect(onMuteToggled);
|
||||
|
||||
Script.scriptEnding.connect(function () {
|
||||
if (onAudioScreen) {
|
||||
|
@ -78,7 +78,7 @@ Script.scriptEnding.connect(function () {
|
|||
}
|
||||
button.clicked.disconnect(onClicked);
|
||||
tablet.screenChanged.disconnect(onScreenChanged);
|
||||
AudioDevice.muteToggled.disconnect(onMuteToggled);
|
||||
Audio.mutedChanged.disconnect(onMuteToggled);
|
||||
tablet.removeButton(button);
|
||||
});
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
Script.scriptEnding.connect(cleanup);
|
||||
|
||||
function update(dt) {
|
||||
if (!AudioDevice.getMuted()) {
|
||||
if (!Audio.muted) {
|
||||
if (hasOverlay()) {
|
||||
deleteOverlay();
|
||||
}
|
||||
|
@ -47,7 +47,7 @@
|
|||
createOverlay();
|
||||
} else {
|
||||
updateOverlay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getOffsetPosition() {
|
||||
|
@ -98,7 +98,7 @@
|
|||
|
||||
function cleanup() {
|
||||
deleteOverlay();
|
||||
AudioDevice.muteToggled.disconnect(onMuteToggled);
|
||||
Audio.muted.disconnect(onMuteToggled);
|
||||
Script.update.disconnect(update);
|
||||
}
|
||||
}()); // END LOCAL_SCOPE
|
||||
|
|
|
@ -196,9 +196,9 @@ MyAvatar.wentActive.connect(setActiveProperties)
|
|||
|
||||
function setAwayProperties() {
|
||||
isAway = true;
|
||||
wasMuted = AudioDevice.getMuted();
|
||||
wasMuted = Audio.muted;
|
||||
if (!wasMuted) {
|
||||
AudioDevice.toggleMute();
|
||||
Audio.muted = !Audio.muted;
|
||||
}
|
||||
MyAvatar.setEnableMeshVisible(false); // just for our own display, without changing point of view
|
||||
playAwayAnimation(); // animation is still seen by others
|
||||
|
@ -221,7 +221,7 @@ function setAwayProperties() {
|
|||
function setActiveProperties() {
|
||||
isAway = false;
|
||||
if (!wasMuted) {
|
||||
AudioDevice.toggleMute();
|
||||
Audio.muted = !Audio.muted;
|
||||
}
|
||||
MyAvatar.setEnableMeshVisible(true); // IWBNI we respected Developer->Avatar->Draw Mesh setting.
|
||||
stopAwayAnimation();
|
||||
|
|
|
@ -33,8 +33,8 @@ Audio.disconnected.connect(function(){
|
|||
Audio.playSound(disconnectSound, soundOptions);
|
||||
});
|
||||
|
||||
AudioDevice.muteToggled.connect(function () {
|
||||
if (AudioDevice.getMuted()) {
|
||||
Audio.mutedChanged.connect(function () {
|
||||
if (Audio.muted) {
|
||||
Audio.playSound(micMutedSound, soundOptions);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
//
|
||||
// 1. Set the Event Connector at the bottom of the script.
|
||||
// example:
|
||||
// AudioDevice.muteToggled.connect(onMuteStateChanged);
|
||||
// Audio.mutedChanged.connect(onMuteStateChanged);
|
||||
//
|
||||
// 2. Create a new function to produce a text string, do not include new line returns.
|
||||
// example:
|
||||
|
@ -34,7 +34,7 @@
|
|||
// var muteState,
|
||||
// muteString;
|
||||
//
|
||||
// muteState = AudioDevice.getMuted() ? "muted" : "unmuted";
|
||||
// muteState = Audio.muted ? "muted" : "unmuted";
|
||||
// muteString = "Microphone is now " + muteState;
|
||||
// createNotification(muteString, NotificationType.MUTE_TOGGLE);
|
||||
// }
|
||||
|
|
|
@ -1,215 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
//
|
||||
// audioDeviceExample.js
|
||||
// examples
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 3/22/14
|
||||
// Copyright 2013 High Fidelity, Inc.
|
||||
//
|
||||
// This is an example script that demonstrates use of the Menu object
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
(function() { // BEGIN LOCAL_SCOPE
|
||||
|
||||
const INPUT = "Input";
|
||||
const OUTPUT = "Output";
|
||||
const SELECT_AUDIO_SCRIPT_STARTUP_TIMEOUT = 300;
|
||||
//
|
||||
// VAR DEFINITIONS
|
||||
//
|
||||
var debugPrintStatements = true;
|
||||
const INPUT_DEVICE_SETTING = "audio_input_device";
|
||||
const OUTPUT_DEVICE_SETTING = "audio_output_device";
|
||||
var audioDevicesList = []; // placeholder for menu items
|
||||
var wasHmdActive = false; // assume it's not active to start
|
||||
var switchedAudioInputToHMD = false;
|
||||
var switchedAudioOutputToHMD = false;
|
||||
var previousSelectedInputAudioDevice = "";
|
||||
var previousSelectedOutputAudioDevice = "";
|
||||
|
||||
var interfaceInputDevice = "";
|
||||
var interfaceOutputDevice = "";
|
||||
|
||||
//
|
||||
// BEGIN FUNCTION DEFINITIONS
|
||||
//
|
||||
function debug() {
|
||||
if (debugPrintStatements) {
|
||||
print.apply(null, [].concat.apply(["selectAudioDevice.js:"], [].map.call(arguments, JSON.stringify)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function setupAudioMenus() {
|
||||
// menu events can be triggered asynchronously; skip them for 200ms to avoid recursion and false switches
|
||||
removeAudioMenus();
|
||||
|
||||
// Setup audio input devices
|
||||
Menu.addSeparator("Audio", "Input Audio Device");
|
||||
var currentInputDevice = AudioDevice.getInputDevice()
|
||||
for (var i = 0; i < AudioDevice.inputAudioDevices.length; i++) {
|
||||
var audioDeviceMenuString = "Use " + AudioDevice.inputAudioDevices[i] + " for Input";
|
||||
Menu.addMenuItem({
|
||||
menuName: "Audio",
|
||||
menuItemName: audioDeviceMenuString,
|
||||
isCheckable: true,
|
||||
isChecked: AudioDevice.inputAudioDevices[i] == currentInputDevice
|
||||
});
|
||||
audioDevicesList.push(audioDeviceMenuString);
|
||||
}
|
||||
|
||||
// Setup audio output devices
|
||||
Menu.addSeparator("Audio", "Output Audio Device");
|
||||
var currentOutputDevice = AudioDevice.getOutputDevice()
|
||||
for (var i = 0; i < AudioDevice.outputAudioDevices.length; i++) {
|
||||
var audioDeviceMenuString = "Use " + AudioDevice.outputAudioDevices[i] + " for Output";
|
||||
Menu.addMenuItem({
|
||||
menuName: "Audio",
|
||||
menuItemName: audioDeviceMenuString,
|
||||
isCheckable: true,
|
||||
isChecked: AudioDevice.outputAudioDevices[i] == currentOutputDevice
|
||||
});
|
||||
audioDevicesList.push(audioDeviceMenuString);
|
||||
}
|
||||
}
|
||||
|
||||
function removeAudioMenus() {
|
||||
Menu.removeSeparator("Audio", "Input Audio Device");
|
||||
Menu.removeSeparator("Audio", "Output Audio Device");
|
||||
|
||||
for (var index = 0; index < audioDevicesList.length; index++) {
|
||||
if (Menu.menuItemExists("Audio", audioDevicesList[index])) {
|
||||
Menu.removeMenuItem("Audio", audioDevicesList[index]);
|
||||
}
|
||||
}
|
||||
|
||||
Menu.removeMenu("Audio > Devices");
|
||||
|
||||
audioDevicesList = [];
|
||||
}
|
||||
|
||||
function onDevicechanged() {
|
||||
debug("System audio devices changed. Removing and replacing Audio Menus...");
|
||||
setupAudioMenus();
|
||||
}
|
||||
|
||||
function onMenuEvent(audioDeviceMenuString) {
|
||||
if (Menu.isOptionChecked(audioDeviceMenuString) &&
|
||||
(audioDeviceMenuString !== interfaceInputDevice &&
|
||||
audioDeviceMenuString !== interfaceOutputDevice)) {
|
||||
AudioDevice.setDeviceFromMenu(audioDeviceMenuString)
|
||||
}
|
||||
}
|
||||
|
||||
function onCurrentDeviceChanged() {
|
||||
debug("System audio device switched. ");
|
||||
interfaceInputDevice = "Use " + AudioDevice.getInputDevice() + " for Input";
|
||||
interfaceOutputDevice = "Use " + AudioDevice.getOutputDevice() + " for Output";
|
||||
for (var index = 0; index < audioDevicesList.length; index++) {
|
||||
if (audioDevicesList[index] === interfaceInputDevice ||
|
||||
audioDevicesList[index] === interfaceOutputDevice) {
|
||||
if (Menu.isOptionChecked(audioDevicesList[index]) === false)
|
||||
Menu.setIsOptionChecked(audioDevicesList[index], true);
|
||||
} else {
|
||||
if (Menu.isOptionChecked(audioDevicesList[index]) === true)
|
||||
Menu.setIsOptionChecked(audioDevicesList[index], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function restoreAudio() {
|
||||
if (switchedAudioInputToHMD) {
|
||||
debug("Switching back from HMD preferred audio input to: " + previousSelectedInputAudioDevice);
|
||||
AudioDevice.setInputDeviceAsync(previousSelectedInputAudioDevice)
|
||||
switchedAudioInputToHMD = false;
|
||||
}
|
||||
if (switchedAudioOutputToHMD) {
|
||||
debug("Switching back from HMD preferred audio output to: " + previousSelectedOutputAudioDevice);
|
||||
AudioDevice.setOutputDeviceAsync(previousSelectedOutputAudioDevice)
|
||||
switchedAudioOutputToHMD = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
function checkHMDAudio() {
|
||||
// HMD Active state is changing; handle switching
|
||||
if (HMD.active != wasHmdActive) {
|
||||
debug("HMD Active state changed!");
|
||||
|
||||
// We're putting the HMD on; switch to those devices
|
||||
if (HMD.active) {
|
||||
debug("HMD is now Active.");
|
||||
var hmdPreferredAudioInput = HMD.preferredAudioInput();
|
||||
var hmdPreferredAudioOutput = HMD.preferredAudioOutput();
|
||||
debug("hmdPreferredAudioInput: " + hmdPreferredAudioInput);
|
||||
debug("hmdPreferredAudioOutput: " + hmdPreferredAudioOutput);
|
||||
|
||||
if (hmdPreferredAudioInput !== "") {
|
||||
debug("HMD has preferred audio input device.");
|
||||
previousSelectedInputAudioDevice = Settings.getValue(INPUT_DEVICE_SETTING);
|
||||
debug("previousSelectedInputAudioDevice: " + previousSelectedInputAudioDevice);
|
||||
if (hmdPreferredAudioInput != previousSelectedInputAudioDevice) {
|
||||
switchedAudioInputToHMD = true;
|
||||
AudioDevice.setInputDeviceAsync(hmdPreferredAudioInput)
|
||||
}
|
||||
}
|
||||
if (hmdPreferredAudioOutput !== "") {
|
||||
debug("HMD has preferred audio output device.");
|
||||
previousSelectedOutputAudioDevice = Settings.getValue(OUTPUT_DEVICE_SETTING);
|
||||
debug("previousSelectedOutputAudioDevice: " + previousSelectedOutputAudioDevice);
|
||||
if (hmdPreferredAudioOutput != previousSelectedOutputAudioDevice) {
|
||||
switchedAudioOutputToHMD = true;
|
||||
AudioDevice.setOutputDeviceAsync(hmdPreferredAudioOutput)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
debug("HMD no longer active. Restoring audio I/O devices...");
|
||||
restoreAudio();
|
||||
}
|
||||
}
|
||||
wasHmdActive = HMD.active;
|
||||
}
|
||||
|
||||
//
|
||||
// END FUNCTION DEFINITIONS
|
||||
//
|
||||
|
||||
//
|
||||
// BEGIN SCRIPT BODY
|
||||
//
|
||||
// Wait for the C++ systems to fire up before trying to do anything with audio devices
|
||||
Script.setTimeout(function () {
|
||||
debug("Connecting deviceChanged(), displayModeChanged(), and switchAudioDevice()...");
|
||||
AudioDevice.deviceChanged.connect(onDevicechanged);
|
||||
AudioDevice.currentInputDeviceChanged.connect(onCurrentDeviceChanged);
|
||||
AudioDevice.currentOutputDeviceChanged.connect(onCurrentDeviceChanged);
|
||||
HMD.displayModeChanged.connect(checkHMDAudio);
|
||||
Menu.menuItemEvent.connect(onMenuEvent);
|
||||
debug("Setting up Audio I/O menu for the first time...");
|
||||
setupAudioMenus();
|
||||
debug("Checking HMD audio status...")
|
||||
checkHMDAudio();
|
||||
}, SELECT_AUDIO_SCRIPT_STARTUP_TIMEOUT);
|
||||
|
||||
debug("Connecting scriptEnding()");
|
||||
Script.scriptEnding.connect(function () {
|
||||
restoreAudio();
|
||||
removeAudioMenus();
|
||||
Menu.menuItemEvent.disconnect(onMenuEvent);
|
||||
HMD.displayModeChanged.disconnect(checkHMDAudio);
|
||||
AudioDevice.currentInputDeviceChanged.disconnect(onCurrentDeviceChanged);
|
||||
AudioDevice.currentOutputDeviceChanged.disconnect(onCurrentDeviceChanged);
|
||||
AudioDevice.deviceChanged.disconnect(onDevicechanged);
|
||||
});
|
||||
|
||||
//
|
||||
// END SCRIPT BODY
|
||||
//
|
||||
|
||||
}()); // END LOCAL_SCOPE
|
Loading…
Reference in a new issue