isSpatialAudioEnabled
Check whether spatial audio is on. The 3D methods for sounds and the listener do nothing while this is false, so check it when a position change has no effect.
isSpatialAudioEnabled(): boolean;
Parameters
This method takes no parameters.
Returns
boolean: true when spatialAudio in the hub config is true and the browser supports spatial audio. Otherwise false.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('rain', '/audio/rain.mp3');
if (soundHub.isSpatialAudioEnabled()) {
soundHub.play('rain', { loop: true });
soundHub.setSpatialPosition(-3, 0, -2, 'rain');
} else {
// Fall back to a stereo pan
soundHub.play('rain', { loop: true, pan: -0.6 });
}
Good to know
spatialAudioistrueby default, so in a supporting browser this istrueunless you passspatialAudio: falseto the constructor.- When the browser lacks support, the constructor switches
spatialAudiooff for you. setSpatialPosition,setSpatialOrientation,setListenerPositionandsetListenerOrientationcheck this and return early. The master panner methods, such assetMasterSpatialPosition, do not.
See also
isSpatialAudioSupported: only the browser check.isSpatialAudioActive: whether one sound is positioned in 3D.soundHubConfig: thespatialAudiooption.