q5play
    Preparing search index...

    Function loadSound

    • 🔊 Loads audio data from a file and returns a Sound object.

      Use functions like play, pause, and stop to control playback. Note that sounds can only be played after the first user interaction with the page!

      Set volume to a value between 0 (silent) and 1 (full volume). Set pan to a value between -1 (left) and 1 (right) to adjust the sound's stereo position. Set loop to true to loop the sound.

      Use loaded, paused, and ended to check the sound's status.

      The entire sound file must be loaded before playback can start, use await to wait for a sound to load. To stream larger audio files use the loadAudio function instead.

      Parameters

      • url: string

        sound file

      Returns Sound & PromiseLike<Sound>

      sound

      await Canvas(200);

      let sound = loadSound('/assets/jump.wav');
      sound.volume = 0.3;

      q5.mousePressed = function () {
      sound.play();
      };