Skip to main content

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​

See also​