javascriptsoundmanager2

How to loop audio in soundmanger2


How can we loop the same audio file in soundamanager2 ??

this is my sample code

function playSound(url) {
            soundManager.setup({
            url: 'swf',
            onready: function() {
                 soundManager.createSound({
                 id: 'samplesound',
                 url: url,
                 volume: 100
                 });
                 soundManager.play('samplesound');
                 }
            }); 
        }

calling it from a tag like

<a href='javascrit:void(0);' onclick='playSound('url');'></a>

can anyone guide me to loop this sound continuously for respective times ??

Thanks for the help...


Solution

  • You can loop the sound using the play command

    The following should play the sound 3 times

    soundManager.play('samplesound',{loops: 3});
    

    a hack to get the loops working could be

    var loops = 3;
    var looped = 0;
        soundManager.createSound({
                         id: 'samplesound',
                         url: url,
                         volume: 100,
                          onfinish:function() { 
                             if(looped<loops){
                                 soundManager.play('samplesound'); 
                                 looped++; 
                              } else{   
                                 looped = 0;
                              }
                          )}
                         });
    

    see

    http://www.schillmania.com/projects/soundmanager2/demo/api/

    and

    http://www.schillmania.com/projects/soundmanager2/doc/#smsoundmethods