Reference loadSound()

loadSound()

loadSound() returns a new p5.SoundFile from a specified path. If called during preload(), the p5.SoundFile will be ready to play in time for setup() and draw(). If called outside of preload, the p5.SoundFile will not be ready immediately, so loadSound accepts a callback as the second parameter. Using a local server is recommended when loading external files.

Examples

Syntax

loadSound(path, [successCallback], [errorCallback], [whileLoading])

Parameters

path
String|Array:

Path to the sound file, or an array with paths to soundfiles in multiple formats i.e. ['sound.ogg', 'sound.mp3']. Alternately, accepts an object: either from the HTML5 File API, or a p5.File.

successCallback
Function:

Name of a function to call once file loads

errorCallback
Function:

Name of a function to call if there is an error loading the file.

whileLoading
Function:

Name of a function to call while file is loading. This function will receive the percentage loaded so far, from 0.0 to 1.0.

Returns

SoundFile: Returns a p5.SoundFile
Notice any errors or typos? Please let us know. Please feel free to edit lib/addons/p5.sound.js and open a pull request!

Related References