isSpatialAudioSupported
Check whether the browser can do spatial audio at all, regardless of the config.
isSpatialAudioSupported(): boolean;
Parameters
This method takes no parameters.
Returns
boolean: true when the browser has an AudioContext, a PannerNode and an audio listener with positionX, positionY and positionZ params. Otherwise false.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
if (!soundHub.isSpatialAudioSupported()) {
console.log('No 3D audio in this browser, using stereo panning instead.');
}
Good to know
- The result is worked out once and cached for the lifetime of the hub.
- It probes the hub's own
AudioContextlistener rather than creating a throwaway context, since browsers cap how many contexts can be open. - A browser with only the older
setPositionmethod on its listener, such as old Safari, counts as unsupported. Spatial audio is then switched off. - Any error during the check is caught and counts as unsupported.
See also
isSpatialAudioEnabled: supported and switched on in the config.- Spatial audio: the overview.