audio5js icon indicating copy to clipboard operation
audio5js copied to clipboard

any method to clear the event queue of specific event?

Open kaikaiiiiiii opened this issue 7 years ago • 4 comments

like ...

var audio5js = new Audio5(); audio5js.on('timeupdate',fn1,this); audio5js.on('timeupdate',fn2,this); audio5js.on('timeupdate',fn3,this); audio5js.clear('timeupdate')

kaikaiiiiiii avatar May 16 '18 05:05 kaikaiiiiiii

yes - audio5js.off('eventName') - please look at the source code

zohararad avatar May 16 '18 05:05 zohararad

Thanks for reply. I've read the source code before. I notice that it must be sub === fn to unsubscribe an event. But my situation's a little bit different.

I wrote a component "click to play a sentence", and loop it for many sentences.

They share a same audio5 instance, which is the easiest way to make the page "only one sentence playing at a time, and every new click will cut the previous sentence and start this new one".

The question is, the component B can't remove the event subed by component A, due to the sub === fn logic.

I know in vue the best and regular way is to $emit a event to it's father and then tell all other component to off their own event.

But I still think it's also a normal function to remove all events at once, no matter who regi-ed them. The situation should be normal in music list or something like that.

kaikaiiiiiii avatar May 16 '18 05:05 kaikaiiiiiii

If I'm honest, at this day and age, using Audio5js seems a bit redundant as all the modern browsers support HTML5 Audio.

You can do one of the following

  • Use native HTML audio
  • register a one-shot event listener and re-register if needed
  • Send a pull request with changes you think are appropriate, as long as it doesn't break current functionality

zohararad avatar May 16 '18 06:05 zohararad

Well, I used it before, and still think it's easier to use than native audio in many situation. Sugar always sweet.

And thanks for your work, especially when that time I was a fool who can't read any complex code. In that time you can't image how excited when I found that I only need to write a5.load(url) & a5.play().

I'll try the third advice a bit later.

kaikaiiiiiii avatar May 16 '18 06:05 kaikaiiiiiii