Warz
Warz

Reputation: 7766

Loop binding to find number of loops

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?

Upvotes: 2

Views: 121

Answers (2)

Amith George
Amith George

Reputation: 5916

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.

Upvotes: 0

omma2289
omma2289

Reputation: 54639

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

Upvotes: 0

Related Questions