Audio loop and sound position

Hey I just wanted to give a little heads up that if you play a sound at a position, it won’t loop until the full length of the track has elapsed, despite starting later.

That is to say, if you play a 2 minute sound at 30 seconds in, then there will be a 30 second silent gap before it loops.

Hey I managed to fix this myself by editing AudioSource.hx and editing
private function timer_onRun () to reset offset = 0;
This means that when the sound is about to loop it won’t use the original offset put in.
This has removed the blank ‘gap’ during looping with an offset.

It’s strange, it appears to handle offset alright. It tells OpenAL to play, then sets currentTime to 0 (which should set the play position to 0 + offset). The timer should then run for length - currentTime, which should be the total length (minus the offset0 and the current play position (minus the offset).

What happens if you change line 198 from timer = new Timer (length - currentTime); to timer = new Timer (length - time);?

It looks like time is set to currentTime when it is created so that change didn’t make any difference.

So it might be that timer.run isn’t updated with the newer position? As if you change the position after playing a song, you still need to wait out the full original duration of the track?

Oh, so perhaps we need to restart the Timer when the play position is changed, that would make sense.

Its unfortunate we need a Timer to get an idea of when a track is finished, but alas, I don’t think there’s a way to get OpenAL notifications

That sounds like a great solution! :slight_smile:
Yeah Timers aren’t the best, but the tracks have never felt out of sync and the tracks loop perfectly well.
Glad we were able to get to the bottom of it.

Could you try this updated file, here?

I think this may have resolved the problem, but I don’t have enough tests to know for sure that it’s correct, yet

Thanks! :slight_smile:

Haha brilliant! Yup, I can confirm that has fixed the issue! Thanks so much.

1 Like