Most visited

Recently visited

Sound

public class Sound
extends Object

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


Viro provides a full-featured audio engine. Sprinkling environments with sound helps to add true immersion to your scenes; they draw the listener's attention and provide cues on where to look next. Viro supports three forms of sound: stereo (for music and non-spatial sound effects), spatial (where the sound is positioned within the scene graph), and sound fields (for atmospheric background noise).

Sound is the class for basic stereo sounds.

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

Summary

Nested classes

interface Sound.PlaybackListener

Callback interface for responding to Sound events. 

Public constructors

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

Construct a new Sound.

Public methods

void dispose()

Release native resources associated with this Sound.

boolean getLoop()

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

Sound.PlaybackListener getPlaybackListener()

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

float getVolume()

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

boolean isLoading()

Return true if the Sound is loading.

boolean isMuted()

Return true if the Sound is currently muted.

boolean isPaused()

Return true if the Sound is paused.

boolean isPlaying()

Return true if the Sound is currently playing.

void pause()

Pause the Sound.

void play()

Play the Sound.

void seekToTime(float seconds)

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

void setLoop(boolean loop)

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

void setMuted(boolean muted)

Set to true to mute the Sound.

void setPlaybackListener(Sound.PlaybackListener listener)

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

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

Sound

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

Construct a new Sound.

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 Sound.PlaybackListener: Sound.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 Sound.

getLoop

boolean getLoop ()

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

Returns
boolean True if loop is enabled.

getPlaybackListener

Sound.PlaybackListener getPlaybackListener ()

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

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

getVolume

float getVolume ()

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

Returns
float The volume.

isLoading

boolean isLoading ()

Return true if the Sound is loading.

Returns
boolean True if the Sound is loading.

isMuted

boolean isMuted ()

Return true if the Sound is currently muted.

Returns
boolean True if muted.

isPaused

boolean isPaused ()

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

Returns
boolean True if the Sound is paused.

isPlaying

boolean isPlaying ()

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

Returns
boolean True if the Sound is playing.

pause

void pause ()

Pause the Sound.

play

void play ()

Play the Sound.

seekToTime

void seekToTime (float seconds)

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

Parameters
seconds float: The seek position in seconds.

setLoop

void setLoop (boolean loop)

Set to true to make the Sound 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 Sound.

Parameters
muted boolean: True to mute.

setPlaybackListener

void setPlaybackListener (Sound.PlaybackListener listener)

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

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

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!