0
\$\begingroup\$

I am passing a clip to play on the audio source. Next, I wait for the audio to finish to invoke the next action.

But the waiting loop never ends. Once the audio clip ends, the time I read from audioSource.time restarts from the beginning without playing the clip (so it's not audibly looping).

I've tried checking the condition audiosource.isPlaying, but this is never false, so it stays in the loop.

IEnumerator PlayAudioClip(AudioClip clp)
{
    audioSource.clip = clp;
    audioSource.Play();
    while (audioSource.isPlaying)
    {
        Debug.Log("Audio Playing "+audioSource.time + ", " + clp.length);
        yield return new WaitForEndOfFrame();
    }
    //Doing some action
}

In this screenshot, you can see the time get to the end and start over:

Sample debug output, showing time ticking forward, then starting over

Note: It's working as expected in the editor. It's not working only in the WebGL Build.

I am using Unity 2021.3.5f1

\$\endgroup\$
3
  • \$\begingroup\$ While maybe not the direct solution, since you know how long the clip is with clp.length, instead of using audioSource.isPlaying you could just use a timer in your while condition and continue once the timer is bigger than the clip time \$\endgroup\$
    – Zibelas
    Sep 22 at 11:09
  • \$\begingroup\$ Please remember to read tag descriptions. Unity has not supported the deprecated language unityscript in the better part of a decade. The code you've written there is c#. It's still C#, even if you're writing it in a Unity game. \$\endgroup\$
    – DMGregory
    Sep 22 at 11:57
  • \$\begingroup\$ Audio has been really funky in webgl for a long time, there are some controls that haven't worked in various unity versions (time, pitch, to name a few). I personally have a lot of comments in my audio code that rules out doing operations on webgl. For what you're looking for, I'd use audio length, and check the duration since you called play like @Zibelas mentioned. That's pretty standard for webgl from what I've seen. \$\endgroup\$ Sep 23 at 11:13

0

You must log in to answer this question.

Browse other questions tagged .