diff --git a/src/hub.js b/src/hub.js index abadc2fd93..542d808b58 100644 --- a/src/hub.js +++ b/src/hub.js @@ -576,21 +576,13 @@ function handleHubChannelJoined(entryManager, hubChannel, messageDispatch, data) // Mute media until the scene has been fully loaded. // We intentionally want voice to be unmuted. - const { globalMediaVolume } = APP.store.state.preferences; - APP.store.update({ - preferences: { - globalMediaVolume: 0 - } - }); + const audioSystem = scene.systems["hubs-systems"].audioSystem; + audioSystem.setMediaGainOverride(0); remountUI({ messageDispatch: messageDispatch, onSendMessage: messageDispatch.dispatch, onLoaded: () => { - APP.store.update({ - preferences: { - globalMediaVolume - } - }); + audioSystem.setMediaGainOverride(1); store.executeOnLoadActions(scene); }, onMediaSearchResultEntrySelected: (entry, selectAction) => diff --git a/src/systems/audio-system.js b/src/systems/audio-system.js index 0581d9adc0..473f1ce9ca 100644 --- a/src/systems/audio-system.js +++ b/src/systems/audio-system.js @@ -136,6 +136,7 @@ export class AudioSystem { this.outboundGainNode.connect(this.outboundAnalyser); this.outboundAnalyser.connect(this.mediaStreamDestinationNode); this.audioContextNeedsToBeResumed = false; + this.mediaGainOverride = 1; this.mediaGain = this.audioContext.createGain(); this.mixer = { @@ -165,6 +166,11 @@ export class AudioSystem { window.APP.store.addEventListener("statechanged", this.onPrefsUpdated); } + setMediaGainOverride(gain) { + this.mediaGainOverride = gain; + this.updatePrefs(); + } + addStreamToOutboundAudio(id, mediaStream) { if (this.audioNodes.has(id)) { this.removeStreamFromOutboundAudio(id); @@ -205,7 +211,7 @@ export class AudioSystem { updatePrefs() { const { globalVoiceVolume, globalMediaVolume, globalSFXVolume } = window.APP.store.state.preferences; - let newGain = globalMediaVolume / 100; + let newGain = this.mediaGainOverride * (globalMediaVolume / 100); this.mixer[SourceType.MEDIA_VIDEO].gain.setTargetAtTime(newGain, this.audioContext.currentTime, GAIN_TIME_CONST); newGain = globalSFXVolume / 100;