AudioModule

The AudioModule class enables sound effects.

Example

//==============================================================================
// The following example demonstrates how to control audio playback by tapping
// on the screen.
//
// Project setup:
// - Import an audio file (M4A, Mono, 44.1kHz, 16 bit)
// - Create an audio playback controller and set the audio to the imported file
// - Insert a speaker and set the audio to the playback controller
// - Add the Tap Gesture capability to the project under Touch Gestures
//==============================================================================

// Load in the required modules
const Audio = require('Audio');
const TouchGestures = require('TouchGestures');

// Locate the playback controller in the Assets
const playbackController =
Audio.getPlaybackController('Audio Playback Controller');

// Loop the playback controller
playbackController.loop();

//==============================================================================
// Start and stop the audio by tapping on the screen
//==============================================================================

// Create a boolean to determine if the audio is playing
var isAudioPlaying = true;

// Subscribe to tap gestures on the screen
TouchGestures.onTap().subscribe(function() {

  // If the audio is stopped, play it, if it's playing, stop it
  if (!isAudioPlaying) {
    playbackController.play();
  } else {
    playbackController.stop();
  }

  // Update the boolean
  isAudioPlaying = !isAudioPlaying;

});

Properties

This module exposes no properties.

Methods

MethodDescription

getPlaybackController

getPlaybackController(name: String): PlaybackController Get a playback controller from assets by name.

play

play(audioSource: AudioSource): void

Creates a new playing instance of the sound associated with this AudioSource.

stopAll

stopAll(audioSource: AudioSource): void

Stops all playing instances of this AudioSource.

Classes

ClassDescription

PlaybackController

The PlaybackController class enables control of audio playback.