English description | Описание на русском
JavaScript plugin for playing sounds on user actions and page events.
Today websites are full of events (new mail, new chat-message, content update etc.). Often it is not enough to indicate this events only visually to get user attention. You need sounds! This library, made for playing small sounds, will help you with this task.
- Ion.Sound freely distributed under terms of MIT licence.
- 25 free sounds included
- Google Chrome
- Mozilla Firefox
- Microsoft Internet Explorer 9.0+
- Opera 12.16+
- Safari 5.1+ (Safari on Windows requires QuickTime to play sounds)
- iOS Safari and others (with some restrictions)
- Android Google Chrome and others (with some restrictions also)
- WP8 Internet Explorer
- 2 versions of plugin: jQuery and standalone
Import this libraries:
- jquery.js - optional
- ion.sound.min.js
Prepare sound-files (25 sounds are included) and put them in some folder (eg. "sounds"):
- my_cool_sound.mp3
- my_cool_sound.ogg
It is not enough to have only Mp3-file, you should make Ogg-file too, because not all browsers support Mp3.
You can easily convert you Mp3-s to Ogg-s at Media.io or at CloudConvert.org.
- bower install ionsound
To initialise plugin call this method:
ion.sound({
sounds: [
{
name: "my_cool_sound"
},
{
name: "notify_sound",
volume: 0.2
},
{
name: "alert_sound",
volume: 0.3,
preload: false
}
],
volume: 0.5,
path: "sounds/",
preload: true
});And play sound!
// Simple
ion.sound.play("my_cool_sound");| Settings | Default | Description |
|---|---|---|
| sounds | - |
You should set your own sounds collection here. This is an array of objects. Sound object structure:name: "sound_name" name of the sound file, without extension, !requiredvolume: 0.2 override default volumepreload: true override default preload setting
|
| path | - | Example: "sounds/". Optional property, set path to folder with sounds, if not set will be the same with html file. |
| preload | false | Optional property, if set to true, will try to preload that sound file on page load. |
| volume | 0.5 | Optional property, will set base volume from 0.0 to 1.0 |
An example of a customised plugin:
ion.sound({
sounds: [
{
name: "message_alert",
volume: 1.0
},
],
path: "sounds/",
preload: true
});// Simple
ion.sound.play("my_cool_sound");
// Change volume and play
ion.sound.play("my_cool_sound", {
volume: 0.9
});
// Loop sound playback
ion.sound.play("my_cool_sound", {
loop: true
});
// Repeat sound for 3 times and reset volume
ion.sound.play("my_cool_sound", {
volume: 0.2,
loop: 3
});// pause sound by name
ion.sound.pause("my_cool_sound");
// pause all sounds
ion.sound.pause();// stop sound by name
ion.sound.stop("my_cool_sound");
// stop all sounds
ion.sound.stop();// destroy sound by name
ion.sound.destroy("my_cool_sound");
// destroy all sounds
ion.sound.destroy();- jQuery method call:
$.ionSound.method(...); - non-jQuery method call:
ion.sound.method(...);
- 2.0.2: August 08, 2014 - New pause method. Add bower support
- 2.0.1: August 01, 2014 - 2 versions of plugin, jQuery and non-jQuery
- 2.0.0: June 31, 2014 - dropped jQuery dependency, new API, loop sounds feature
- 1.3.0: November 30, 2013 - new methods "stop" and "kill". Ability to reset sound volume
- October 13, 2013 - now you can set individual volume for any sound. Improved test environment
- September 21, 2013 - plugin moved to jQuery namespace, new method and 10 new sounds
- September 08, 2013 - iOS not playing sound bug fix
- September 08, 2013 - Little enhancement
- September 07, 2013 - Plugin release