A component that enables the user play and control mono and stereo sound effects. Refer to Sound under Develop for more information.

Example use:
<ViroSound
    source={require("./sound/mysound.mp3")}
    onFinish={this.onFinishSound}
/>

Props

source (* required)

TypeDescription
ImageSourcePropTypeThe sound source, either a mono or stereo audio file. Supported extensions include .mp3 and .wav.This can also be the key of a preloaded sound. See preloadSounds below for more information.

An asset can be loaded by using require() or { uri: 'https://example.com/your-sound.mp3' }

loop

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

muted

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

onError

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

onFinish

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

paused

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

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.

Methods

seekToTime(timeInSeconds)

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

Parameters

timeInSeconds - The seek position in seconds.

Static Methods

static preloadSounds(soundMap:{[key:string]: string)

Given a map of keys and links to their corresponding sound data, Viro will prefetch each sound and store it locally for quick access, asynchronously. You can then play these sounds later by providing the key in the sound's source attribute. We currently only support external urls (web-based).

Example showing the preloading of two sounds:

ViroSound.preloadSounds({  
  "cube_sound": resolveAssetSource(require("../res/metronome.mp3")),
  "cube_sound_2": "http://www.kozco.com/tech/32.mp3"),
});

static unloadSounds(soundKeys: [string])

Given sound keys, will delete the local prefetched copy of sound data from the application's internal directory.

ViroSound.unloadSounds([ "cube_sound" ]);