loadSound()

Loads a sound into the code's assets

Example

click the link below to play the sound.

def setup():
    ...
    loadSound("/wow-121578.mp3",'WOW')

def draw():
    ...
    assets['WOW'].play()

Syntax

def setup():
    ...
    loadSound("sourceURL",'NAME')

def draw():
    ...
    assets['NAME'].play()
    ...
    assets['NAME'].stop()
InputDescription

sourceURL

web or local URL of sound to be loaded

NAME

name for variable of sound in code

Description

Loads a sound into memory from an external source so that it can be used in code. The sourceURL can be a web address (for example "http://wow-121578.mp3") - this is the usual situation - or the local address if the file is stored with the rest of your code.

Once a sound is loaded (in the example below, using the variable 'NAME' in code), the following functions are available to call on the sound file:

FunctionDescription

assets['NAME'].play()

starts playing the sound

assets['NAME'].stop()

stops playing the sound and resets it

assets['NAME'].pause()

stops playing the sound and pauses it

assets['NAME'].isPlaying()

returns True or False depending on whether the sound is currently already playing

assets['NAME'].volume(V)

adjusts the volume of the sound. V is a decimal value between 0 and 1.

0 is no volume, 1 is maximum volume

Find these documents helpful? Let the people who made them help your child learn to code at Strivemath!

We'd love to hear your Feedback/Comments here.

Last updated