Most visited

Recently visited

SpatialSound

public class SpatialSound
extends Object

java.lang.Object
   ↳ com.viro.core.SpatialSound


SpatialSound is positioned audio that can travel throughout a scene. For example, you can create a SpatialSound that animates along with a bird, chirping as it flies through the scene. SpatialSound is also compatible with reverb effects, which enables you to simulate the acoustic qualities of a wide variety of environments. To use reverb, create a sound room via setSoundRoom(ViroContext, Vector, Scene.AudioMaterial, Scene.AudioMaterial, Scene.AudioMaterial).

For an extended discussion of sound in Viro, refer to the Audio Guide.

Summary

Nested classes

interface SpatialSound.PlaybackListener

Callback interface for responding to SpatialSound events. 

enum SpatialSound.Rolloff

The attenuation function that determines how the volume of the SpatialSound changes with distance from the sound's position. 

Public constructors

SpatialSound(ViroContext viroContext, Uri uri, SpatialSound.PlaybackListener listener)

Construct a new SpatialSound.

Public methods

void dispose()

Release native resources associated with this SpatialSound.

boolean getLoop()

Return true if the SpatialSound is currently set to loop after finishing playback.

SpatialSound.PlaybackListener getPlaybackListener()

Get the SpatialSound.PlaybackListener used to receive callbacks for this SpatialSound.

float getVolume()

Get the volume of the SpatialSound, between 0.0 and 1.0.

boolean isLoading()

Return true if the SpatialSound is loading.

boolean isMuted()

Return true if the SpatialSound is currently muted.

boolean isPaused()

Return true if the SpatialSound is paused.

boolean isPlaying()

Return true if the SpatialSound is currently playing.

void pause()

Pause the SpatialSound.

void play()

Play the SpatialSound.

void seekToTime(float seconds)

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

void setDistanceRolloff(SpatialSound.Rolloff rolloff, float minDistance, float maxDistance)

Specify how this SpatialSound should attenuate in volume with distance from the user.

void setLoop(boolean loop)

Set to true to make the SpatialSound automatically loop to the beginning when playback finishes.

void setMuted(boolean muted)

Set to true to mute the SpatialSound.

void setPlaybackListener(SpatialSound.PlaybackListener listener)

Set the SpatialSound.PlaybackListener, which can be used to respond to SpatialSound loading and playback events.

void setPosition(Vector position)

Set the position of this SpatialSound within the coordinate system of its parent Node.

void setVolume(float volume)

Set the volume to the given value, where 0.0 is mute and 1.0 is the maximum volume.

Public constructors

SpatialSound

SpatialSound (ViroContext viroContext, 
                Uri uri, 
                SpatialSound.PlaybackListener listener)

Construct a new SpatialSound.

Parameters
viroContext ViroContext: The ViroContext is required to play sounds.

uri Uri: The URI of the sound. To load the sound from an Android asset, use URI's of the form file:///android_asset/[asset-name].

listener SpatialSound.PlaybackListener: SpatialSound.PlaybackListener which can be used to respond to sound loading and playback events. May be null.

Public methods

dispose

void dispose ()

Release native resources associated with this SpatialSound.

getLoop

boolean getLoop ()

Return true if the SpatialSound is currently set to loop after finishing playback.

Returns
boolean True if loop is enabled.

getPlaybackListener

SpatialSound.PlaybackListener getPlaybackListener ()

Get the SpatialSound.PlaybackListener used to receive callbacks for this SpatialSound.

Returns
SpatialSound.PlaybackListener The listener, or null if none is attached.

getVolume

float getVolume ()

Get the volume of the SpatialSound, between 0.0 and 1.0.

Returns
float The volume.

isLoading

boolean isLoading ()

Return true if the SpatialSound is loading.

Returns
boolean True if the SpatialSound is loading.

isMuted

boolean isMuted ()

Return true if the SpatialSound is currently muted.

Returns
boolean True if muted.

isPaused

boolean isPaused ()

Return true if the SpatialSound is paused. The SpatialSound can be played by invoking play().

Returns
boolean True if the SpatialSound is paused.

isPlaying

boolean isPlaying ()

Return true if the SpatialSound is currently playing. This returns false if the SpatialSound is loading or paused.

Returns
boolean True if the SpatialSound is playing.

pause

void pause ()

Pause the SpatialSound.

play

void play ()

Play the SpatialSound.

seekToTime

void seekToTime (float seconds)

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

Parameters
seconds float: The seek position in seconds.

setDistanceRolloff

void setDistanceRolloff (SpatialSound.Rolloff rolloff, 
                float minDistance, 
                float maxDistance)

Specify how this SpatialSound should attenuate in volume with distance from the user. The sound will begin attenuating at minDistance and reach zero volume at maxDistance. The volume level of the sound between those two values is determined by the SpatialSound.Rolloff model chosen.

Parameters
rolloff SpatialSound.Rolloff: The SpatialSound.Rolloff which determines how the sound attenuates between minDistance and maxDistance.

minDistance float: The distance at which the sound begins attenuating.

maxDistance float: The distance at which the sound finishes attenuated; e.g, when it reaches zero volume.

setLoop

void setLoop (boolean loop)

Set to true to make the SpatialSound automatically loop to the beginning when playback finishes.

Parameters
loop boolean: True to loop.

setMuted

void setMuted (boolean muted)

Set to true to mute the SpatialSound.

Parameters
muted boolean: True to mute.

setPlaybackListener

void setPlaybackListener (SpatialSound.PlaybackListener listener)

Set the SpatialSound.PlaybackListener, which can be used to respond to SpatialSound loading and playback events.

Parameters
listener SpatialSound.PlaybackListener: The listener to use for this Sound.

setPosition

void setPosition (Vector position)

Set the position of this SpatialSound within the coordinate system of its parent Node.

Parameters
position Vector: The position of this SpatialSound as a Vector.

setVolume

void setVolume (float volume)

Set the volume to the given value, where 0.0 is mute and 1.0 is the maximum volume. The default is 1.0.

Parameters
volume float: The value between 0.0 and 1.0.

Hooray!