2

I could not find this in the buzz.js documentation but is there any bindings for the loop event. Something like

soundObject.bind('looping', function(e){

});

I am looking to see how many times the sound object has looped, if anyone with knowledge around this library has a workaround that would also help. I tried to bind to the ended event but that doesn't work?

EDIT:

I am thinking as a hack that i could bind to the playing event and use the getPercent() method to see when i have hit 100 and keep a counter to find number of loops?

Warz
  • 7,386
  • 14
  • 68
  • 120

2 Answers2

0

Edit 1:

True. My older answer doesn't function as I thought it might :). Having read the source, they don't seem to trigger any public events. Though they do seem to bind to some private one, ended.buzzloop. I couldn't find the said event being trigger in code, but maybe it might work for you

As @koala suggested, implementing your own loop might turn out to be a better option.


Old answer - doesn't work!

I haven't used buzz.js before. Reading the docs, I found the playing & paused events.

playing

Sent when the media begins to play (either for the first time, after having been paused, or after ending and then restarting).

My idea is to listen to these two events. If playing is raised without a pause having been raised, then you can increment your count.

Amith George
  • 5,806
  • 2
  • 35
  • 53
  • The playing event handler is only called once and then not called again unless paused or ended has occurred. Since `loop()` never calls ended or paused how would my counter increment? – Warz Jul 27 '13 at 20:30
  • Added another suggestion. – Amith George Jul 27 '13 at 21:02
0

Since there are no events that trigger with the loop option, then why not implement your own loop functionality by binding to the ended event and than calling play() again, this way you know when each play has finished.

var loopCount = 0;
var mySound = new buzz.sound("my_cool_sound").bind('ended', function () {
    loopCount++;
    this.play();
}).play();

Demo fiddle

omma2289
  • 54,161
  • 8
  • 64
  • 68