Infinite looping sound?

I am trying to have a sound that loop infinitely.
I saw on some forums that calling,-1) (so with a -1 number of loops) should work. However it doesn’t
By looking at the Audiosource class that handle the playing, we can see that:

if (loops > 0) {
            currentTime = 0;
            play ();
        } else {
            AL.sourceStop (id);
            timer.stop ();

So defining “-1” number of loops is the same as defining “0” (the default). Which explains why the sound doesn’t loop.
So How can I loop a sound infinitely using Openfl (I use unified OpenFL (the default), not the legacy one)

Normally I just pass “10000” and figure that no one’s going to listen ten thousand times in a row.

funny i do the same thing, also 10000, guess that’s the sane cutoff.

in the end, wouldnt it be better to have a loop function though?
say something like sample.loop(true); and sample.loop(false);?
just saying more for ease

OpenFL follows the Flash API, and the Flash API doesn’t define such a function. It’s possible to add functions on top of that, but it isn’t exactly easy.

There are 31536000 seconds in a year. Pass a number thats 10 times this much, will guarantee that your sound will play for years… I guess passing positive infinity from the math class should work too.

No, because that’s a float, and the function requires an int.

I learn something new everyday :slight_smile:

I rmbr there is a Int.MAX_VALUE sort of thing in as3, but I don’t know for haze tho

What you could do is listen on the Event.SOUND_COMPLETE by adding a listener to the SoundChannel variable instance, and when the sound completes, you just simply replay the channel by taking You’d probably have to use as a template to create another Sound instance, as I’m sure of no other way. But that’s one way of “infinitely” playing a sound, not necessarily great for sounds that loop naturally as there may be a small gap in the event loop itself.