Ion.Sound Advanced Demo Page

Feedback and support

If you find some bugs or missing functional in plugins, use Issues page on GitHub

Support

Support ion.RangeSlider «Patreon»
Bitcoin 13vdgT6EoAVupdGuLhE4ABW245NTixAj1G

Adv

Ion.Sound customizing demos

Preloading sounds

ion.sound({
    sounds: [
        {
            name: "metal_plate",
            preload: true
        },
        {name: "metal_plate_2"},
        {name: "pop_cork"},
        {name: "snap"}
    ],

    path: "static/sounds/",
    preload: false,
    multiplay: true,
    volume: 0.9,

    scope: this, // optional scope
    ready_callback: myReadyCallback
});

// method to force sound loading
ion.sound.preload("pop_cork");

// using play for non preloaded sound
// will force loading process first
// and only when playback
ion.sound.play("pop_cork");
Ion.Sound has advanced resource loading system. You can preload all or several sounds at the beginning. Or you can choose to preload none at first and decide when to load sounds somethere in your program o game.
Plugin will fire ready callback for each loaded sound. Note that in browsers without Web Audio API support, like Internet Explorer, plugin falls back to HTML5 Audio, and loaded callback will fire when sound is ready to play (without full preload).
Name: metal_plate Loaded:
Play already loaded
Name: metal_plate_2 Loaded:
Preload and then play
Name: pop_cork Loaded:
Preload, play
Name: snap Loaded:
Preload, play

Playing audio sprites

ion.sound({
    sounds: [
        {
            // sprite name
            name: "wd_sprite",

            // sprite parts
            sprite: {
                "intro": [2, 3.4],
                "part1": [13.5, 6.6],
                "part2": [27.8, 1.76],
                "part3": [33, 1.6],
                "end": [44.5, 4.71]
            }
        }
    ],

    path: "static/sounds/",
    preload: true,
    multiplay: false,
    volume: 0.9
});

// controlling sprites
ion.sound.play("wd_sprite", {
    part: "intro"
});
ion.sound.pause("wd_sprite", {
    part: "intro"
});
ion.sound.stop("wd_sprite", {
    part: "intro"
});
// etc.
Ion.Sound supports audio sprites (many sounds packed in to one audio file). To use audio sprite, create "sprite" object, then set each sprite's part like this: "bang": [start time, length] (all values in seconds).
To play this sprite part do this: ion.sound.play("file_name", {part: "bang"}; If you skip "part" property, Ion.Sound will try to play all included sprite's parts at once.
Name: wd_sprite Part: intro
Play, pause, stop
Name: wd_sprite Part: part1
Play, pause, stop
Name: wd_sprite Part: part2
Play, pause, stop
Name: wd_sprite Part: part3
Play, pause, stop
Name: wd_sprite Part: end
Play, pause, stop
Name: wd_sprite Part: all at once
Play, pause or stop all "wd_sprite" parts at once

Create and destroy sound instances

// create sound
ion.sound({
    sounds: [
        {name: "witchdoctor"}
    ],

    path: "static/sounds/",
    preload: true,
    multiplay: false
});

// destroy sound
ion.sound.destroy("witchdoctor");
Any sound can be created when ever you need and, also, can be destroyed after if you will need so. Just call ion.sound.destroy("sound_name"). To destroy all sounds at once, call ion.sound.destroy() without arguments. Destroying audio sprite will destroy all it's parts.
Name: witchdoctor Loaded:
Play, stop

Callbacks

// create sound
ion.sound({
    sounds: [
        {name: "door_bump"},
        {name: "water_droplet_2"},
        {name: "water_droplet_3"}
    ],

    path: "static/sounds/",
    preload: true,
    multiplay: false,

    ready_callback: function (obj) {
        obj.name;     // File name
        obj.alias;    // Alias (if set)
        obj.ext;      // File .ext
        obj.duration; // Seconds
    },
    ended_callback: function (obj) {
        obj.name;     // File name
        obj.alias;    // Alias (if set)
        obj.part;     // Part (if sprite)
        obj.start;    // Start time (sec)
        obj.duration; // Seconds
    }
});

// destroy sound
ion.sound.destroy("witchdoctor");
Ion.Sound supports 2 callbacks: ready_callback (then sound is ready to play) and ended_callback (then sounds playback was ended). Each callback gets the object with sound information.
Name: door_bump Ended: Loaded:
Play
Name: water_droplet_2 Ended: Loaded:
Play
Name: water_droplet_3 Ended: Loaded:
Play
Fork me on GitHub