Smoother sound looping

Hey everyone,

I’ve been using the following code to make the soundtrack for my project loop over and over again until it is told to stop:


function playMusic():void
{
soundtrackChannel = soundtrack.play();
soundtrackChannel.addEventListener(Event.SOUND_COMPLETE, loopMusic);
}

function loopMusic():void
{
if (soundtrackChannel != null)
{
soundtrackChannel.removeEventListener(Event.SOUND_COMPLETE, loopMusic)
playMusic();
}
}

It’s working for me, but it’s not particularly smooth. There’s a bit of a delay between the previous iteration of the loop and the next one - it pauses for a second between loops.

Does anyone have any ideas as to how I can solve this issue?

My project’s almost done now and I’ve had loads of great help from this community, thank you so much for your help!