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)
| Type | Description |
|---|---|
| ImageSourcePropType | The source of a spatial sound. Must be a single-channel audio file. |
loop
| Type | Description |
|---|---|
| boolean | Set to true to loop the spatial sound. This is set to false by default. |
maxDistance
| Type | Description |
|---|---|
| number | A distance after which the audio can not be heard. |
minDistance
| Type | Description |
|---|---|
| number | A distance after which the audio will begin to attenuate until maxDistance where the sound is completely gone. |
muted
| Type | Description |
|---|---|
| boolean | Set to true to mute the spatial sound. This is set to false by default. |
onError
| Type | Description |
|---|---|
| Function | Callback invoked when the 360 Image fails to load. The error message is contained in event.nativeEvent.error |
onFinish
| Type | Description |
|---|---|
| Function | Callback 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
| Type | Description |
|---|---|
| boolean | Set to true to pause the spatial sound. This is set to false by default. |
rolloffModel
| Type | Description |
|---|---|
| "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
| Type | Description |
|---|---|
| number | A 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
| Type | Description |
|---|---|
| [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.
Updated 5 days ago