Closed objarni closed 9 years ago
This could abstractly be viewed as categorising a sound as either a "sample" (think game effect sound), or "music" (think audio tag / media player).
Bump.
It actually looks pretty simple.
This is the code for the music buttons:
sound2.stop().play();
And this is the code for sound fx button:
sound3.play('blast');
I'd agree it is bit confusing when source code on the screen is not 1-to-1 match with actual JS. :)
Thank you but I can only see one api play call?
Below is slightly shortened complete javascript from the http://goldfirestudios.com/blog/104/howler.js-Modern-Web-Audio-Javascript-Library:
$(function(){
hljs.initHighlightingOnLoad();
$('#ex1-play').on('click', function(){
sound1.stop().play();
});
$('#ex1-pause').on('click', function(){
sound1.pause();
});
$('#ex1-stop').on('click', function(){
sound1.stop();
});
$('#ex1-loop').on('click', function(){
sound1.loop(true);
});
$('#ex3-play1').on('click', function(){
sound3.play('blast');
});
$('#ex3-play2').on('click', function(){
sound3.play('laser');
});
$('#ex3-play3').on('click', function(){
sound3.play('winner');
});
});
var sound1 = new Howl({
urls: ['/proj/howlerjs/sound.ogg', '/proj/howlerjs/sound.mp3']
});
var sound3 = new Howl({
urls: ['/proj/howlerjs/sounds.ogg', '/proj/howlerjs/sounds.mp3'],
sprite: {
blast: [0, 2000],
laser: [3000, 700],
winner: [5000, 9000]
}
});
So the API is that, if you use a named fx, api play(id), it is played asynchronosly to any previous instance of the sound, and if you use the play(), no id specified, it discontinues previous playback...?
It could be a lot more explicit in the documentation.
Take a look at the 2.0 branch, this concept should be cleared up much better (though any suggestions for improvements to the new docs are welcome).
What determines whether a sound is played "in parallell" with itself or not? I cannot find it in the documentation on howlerjs.com.
I've asked the same question in the website comments, but get no answer. I'd like to help out documenting this better as I find howler.js to be the most promising JS audio lib I've found so far ...
Reproduce on howlerjs.com: