HomeGuidesAPI ReferenceChangelogDiscussions
Hire a ReactVision Expert 🛠️Launch Studio 🖥️Sponsor on GitHub ❤️Log In
Guides

ViroSpatialSound

A component that represents a sound in 3D space. Must be a single-channel sound (mono) and can be placed within a ViroNode or ViroAnimatedComponent which changes its position relative to the user. Refer to Sound under Develop for more information.

visionOS: not supported. From 3.0.3 the component warns once and renders nothing instead of crashing.

iOS: use 3.2.0 or later. Earlier versions crashed on mount, because the method the component called to create its sound did not exist.

Web, 3.2.2+: sounds play through Web Audio, so they mix with a video that has sound on iPhone, and a sound the browser holds back starts at the first user gesture.

Web, 3.2.3+: spatial sound uses native's rolloff defaults, the listener follows the camera outside AR, and position is in the parent's space.

Example use:
<ViroSpatialSound
    source={require("./sound/mysound.wav")}
    position={[0, 0, -3]}
    onFinish={this.onFinishSound}
/>

Props

source (* required)

TypeDescription
ImageSourcePropTypeThe source of a spatial sound. Must be a single-channel audio file.

loop

TypeDescription
booleanSet to true to loop the spatial sound. This is set to false by default.

maxDistance

TypeDescription
numberA distance after which the audio can not be heard.

minDistance

TypeDescription
numberA distance after which the audio will begin to attenuate until maxDistance where the sound is completely gone.

muted

TypeDescription
booleanSet to true to mute the spatial sound. This is set to false by default.

onError

TypeDescription
FunctionCallback invoked when the 360 Image fails to load. The error message is contained in event.nativeEvent.error

onFinish

TypeDescription
FunctionCallback that is called when the spatial sound is finished playing. This function isn't called at the end of a spatial sound if looping is enabled.

paused

TypeDescription
booleanSet to true to pause the spatial sound. This is set to false by default.

rolloffModel

TypeDescription
"None" | "Linear" | "Logarithmic"The rolloff model which determines how the sound volume will fall off between minDistance and maxDistance. Accepts the following values:

None
Linear
* Logarithmic

volume

TypeDescription
numberA number represented volume from 0 to 1. Max volume is equal to 1. Min volume is equal to 0. This is set to 1 by default.

position

TypeDescription
[number, number, number]Cartesian position of the sound in 3D world space, specified as [x, y, z].

Method

seekToTime(timeInSeconds)

Seek to the given point in the Sound, in seconds.

Parameters

timeInSeconds - The seek position in seconds. From 3.1.0 fractional seconds are honoured; before, they were truncated to whole seconds.