0
\$\begingroup\$

I have an audioSource in which loop is set to true. I am starting it playing by calling playdelayed()

In the editor its plays fine. In a webgl build it does not loop. It just plays once.

Also in firefox it does not start playing at the correct time, it is a good fraction of a second off.

public override void MatchStarted()
{
    Intro.Play();
    Loop.PlayDelayed(Intro.clip.length);
}

PlayScheduled has exactly the same effect.

public override void MatchStarted()
{
    Intro.Play();
    Loop.PlayScheduled(AudioSettings.dspTime + Intro.clip.length);
}

Play(ulong) has the same effect

public override void MatchStarted()
{
    Intro.Play();
    Loop.Play((ulong)(44100 * Intro.clip.length));
}

I'm posting this here seeking workarounds. Any suggestions? As you can see from my code, my use case is a piece of music with an intro and a loop.

...

ps. I have seen some posts saying that if the bitrate is not 44.1 KHz this can cause looping issues on WebGl. The audio file in question is set to override the bitrate to 44.1 in its import settings.

\$\endgroup\$
1
\$\begingroup\$

Ok here is my workaround. I added the intro and loop together into one file. I also added on a little bit more of the start of the loop onto the end, and I made a note of exactly what time the loop should start and end at.

enter image description here

const float startlooptime = 11.875f;
const float endlooptime = 74.375f;

public override void MatchStarted()
{
    Loop.Play();
}

void Update()
{
    if (!Loop.isPlaying) return;

    if (Loop.time > endlooptime) Loop.time = startlooptime + (Loop.time - endlooptime);
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.