Howler.js: Feature Request: loop X number of times

Created on 4 Nov 2015  路  6Comments  路  Source: goldfire/howler.js

Looping is cool! What about looping a specific number of times?

To me, howler has some real potential even though there are still lots of limitations when used as a music player.. keep at it Goldfire, every time it's better and better!

Most helpful comment

@momander any reason why you can't use onend to stop the loop after a predetermined number of loops?

var counter = 0;
var maxIterations = 3;

var howl = new Howl({
  src: [soundSrc],
  loop: true,
  autoplay: true,
  rate: 2.5,
  onend: function() {
    counter++;
    console.log("Finished iteration " + counter);
    if (counter === maxIterations - 1) {
      console.log("Last time!")
      howl.loop(false);
    }
  }
});

Also see: working jsbin example

All 6 comments

howler.js isn't meant to be specifically a music player, it is intended to be general-use. It should be trivial to implement this in an app if needed, I'm not sure it makes sense to include it in core. I do plan on creating a music player as an example before releasing 2.0.

Hello James, Thank you for your willingness to address my request! I understand your point of view, and more than anything am grateful for your work and product. Sometimes I feel that the fact that it's geared towards general-use may cause limitations for the user. It's like erring on the side of safety and caution when there could be more risks and bold moves to be explored. Although it isn't intended to be a music player, there are certain things inherent to music players that could enhance general use. For example, the ability to easily organize audio clips and more functionality on playback controls.

I appreciate your intention to create a music player as an example, and feel like it would be emulated. It seems that you do have extensive expertise, but something you might consider trivial, such as implementing x number of loops, might be beyond the scope of many users. I hope you take this constructive criticism as a request towards more flexible use of the audio capabilities of howler.js, and a push towards more functional engineering!

Thanks for the feedback! Setting up the example music player will certainly be an exercise in learning, so I'm sure some things will arise out of that :smile:

Hi there, I just wanted to highlight another use case for the "loop X times, then stop" functionality. I am building a web-based game using Howler and the title screen, where you select your mission, plays a melody loop. If the user puts away their laptop or phone while the browser is on the title page, the device will keep playing the melody loop forever. It would be nice if it would stop by itself at some point.

Thanks for building an awesome library!

@momander any reason why you can't use onend to stop the loop after a predetermined number of loops?

var counter = 0;
var maxIterations = 3;

var howl = new Howl({
  src: [soundSrc],
  loop: true,
  autoplay: true,
  rate: 2.5,
  onend: function() {
    counter++;
    console.log("Finished iteration " + counter);
    if (counter === maxIterations - 1) {
      console.log("Last time!")
      howl.loop(false);
    }
  }
});

Also see: working jsbin example

Oh, I didn't know of the onend technique. Thanks for showing me -- I really appreciate it!

Will update my game so the title page only plays the music loop ten times. When I demoed my game last weekend, one attendee was left wondering what the strange sound was coming from her phone late at night. It was my game's music, as she had left the game's title page open in her browser :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SandMoshi picture SandMoshi  路  3Comments

lili21 picture lili21  路  4Comments

st-h picture st-h  路  5Comments

Glutch picture Glutch  路  3Comments

indexofrefraction picture indexofrefraction  路  4Comments