Hivenfour / SeamlessLoop

Reproduce seamless/gapless audio loops on HTML5/JavaScript without specific browser Audio APIs
121 stars 16 forks source link

With Multiple sounds, not looping #4

Open ghost opened 10 years ago

ghost commented 10 years ago

When I use the following code example, the 1st sound is not looping. var loop = new SeamlessLoop();

        loop.addUri('Loading_tune.mp3', 6*1000, 'Loading_tune');
        loop.addUri('background_sound.mp3', 144*1000, 'background_sound');

        loop.callback(function()
        {
            loop.start('Loading_tune');
            loop.start('background_sound');

// After 10s stop only background (Loading_tune should still loop)

            setTimeout(function()
            {
                loop.stop('background_sound');
            }, 10*1000);
        });
brantome commented 9 years ago

Same problem here. Any ideas on how to play multiple loops at the same time ? Thanks

roganoalien commented 5 years ago

Create one seamlessloop object for each sound. Load every sound and call the callback to validate each sound is loaded and then start every sound.

loop1.addUri('/Content/sounds/song2/drums-new.mp3', 20000, "drums");
loop2.addUri('/Content/sounds/song2/bass.mp3', 20000, "bass");
loop3.addUri('/Content/sounds/song2/fxs.mp3', 20000, "fxs");
loop4.addUri('/Content/sounds/song2/guitars.mp3', 20000, "guitars");
loop5.addUri('/Content/sounds/song2/synth.mp3', 20000, "synth");

loop1.callback(function(){
    validator++;
    canPlay(validator);
});
....

canPlay(validator){
    if(validator === 5){
        loop1.start();
        loop2.start();
        loop3.start();
        loop4.start();
        loop4.start();
}