下载地址:https://github.com/goldfire/howler.js
Features
var sound = new Howl({
urls: ['sound.mp3', 'sound.ogg']
}).play();
var sound = new Howl({
urls: ['sound.mp3', 'sound.ogg', 'sound.wav'],
autoplay: true,
loop: true,
volume: 0.5,
onend: function() {
alert('Finished!');
}
});
var sound = new Howl({
urls: ['sounds.mp3', 'sounds.ogg'],
sprite: {
blast: [0, 2000],
laser: [3000, 700],
winner: [5000, 9000]
}
});
// shoot the laser!
sound.play('laser');
Boolean
(true
by default) Set to true
to automatically start playback when sound is loaded.Boolean
(false
by default) Set to true
to force HTML5 Audio. This should be used for large audio files so that you don't have to wait for the full file to be downloaded and decoded before playing.String
(null
by default) howler.js automatically detects your file format from the URL, but you may also specify a format in situations where URL extraction won't work.Boolean
(false
by default) Set to true
to automatically loop the sound forever.Object
({}
by default) Define a sound sprite for the sound. The offset and duration are defined in milliseconds.// Sound sprite definition format
{
key: [offset, duration]
}
Number
(1.0
by default) The volume of the specific track, from 0.0
to 1.0
.Array
([]
by default) The source URLs to the track(s) to be loaded for the sound. These should be in order of preference, howler.js will automatically load the first one that is compatible with the current browser.Function
(function(){}
by default) Fire when the sound finishes playing (if it is looping, it'll fire at the end of each loop).Function
(function(){}
by default) Fires when the sound is loaded.Function
(function(){}
by default) Fires when the sound fails to load.Function
(function(){}
by default) Fires when the sound has been paused.Function
(function(){}
by default) Fires when the sound begins playing.String
(optional) Plays from the defined sprite key.pos
of playback.
Number
(optional) The play instance ID.pos
to 0
.
Number
(optional) The play instance ID.Number
(optional) The play instance ID.Number
(optional) The play instance ID.Number
Volume to fade to (0.0
to 1.0
).Number
Time in milliseconds to fade.Function
(optional) Fires when fade is complete.Number
Volume to fade to (0.0
to 1.0
).Number
Time in milliseconds to fade.Function
(optional) Fires when fade is complete.Number
(optional) The play instance ID.Boolean
(optional) To loop or not to loop, that is the question.Number
(optional) The position to move current playback to.Number
(optional) The play instance ID.Object
(optional) See above for sound sprite definition.x
position to affect the left/right ear panning. Setting the value higher than 1.0
will begin to decrease the volume of the sound as it moves further away. This only works with Web Audio API.
Number
The x-position of the sound.Number
The y-position of the sound.Number
The z-position of the sound.Number
(optional) The play instance ID.Number
(optional) Volume from 0.0
to 1.0
.Number
(optional) The play instance ID.Array
(optional) Changes the source files for this Howl
object.String
Name of event to fire/set.Function
(optional) Define function to fire on event.String
Name of event.Function
(optional) The listener to remove.Howler
object.
Number
(optional) Volume from 0.0
to 1.0
.