Description

Sound management The class uses HTML5 audio but you can use SoundManager 2 http://www.schillmania.com/projects/soundmanager2/.

Use :

Example

Using Sound :

var canvas = CE.defines("canvas_id").
    ready(function() {
        canvas.Scene.call("MyScene");
    });

canvas.Scene.new({
    name: "MyScene",
    materials: {
        sounds: {
            sound_id: "path/to/music.mp3"
        }
    },
    ready: function(stage) {
        canvas.Sound.get("sound_id").play();
    }
});

Here, CanvasEngine fetches the MP3 file in the sound folder. If the browser does not support it (like Firefox), it's OGG or M4A file with the same name will be searched.

  1. First load : path/to/music.mp3
  2. If no supported : path/to/music.ogg
  3. If no supported : path/to/music.m4a

Methods

get

Get the sound. Use API HTML5 Audio or SoundManager (http://www.schillmania.com/projects/soundmanager2/doc/#smsoundmethods)

allStop

Stop all music

stop

`(>= 1.3.0)` Stop a sound. Breaks the sound loop

play

`(>= 1.3.0)` Plays a sound

playOnly

Only play a sound (and other stops)

playLoop

`(>= 1.3.0)` Plays a looping sound

fadeIn

To fade for unmute

fadeOut

To fade for mute

fadeTo

Fade to a final value

Discussion