AudioSource Play and Pause in WebGL

I’m trying to make a button that plays and pauses a song, but sometimes when I pause the song and then click the button the song doesn’t continue where it has to, like if the song jumped forward some seconds. This only happens when it is exported to WebGL (in the Unity Project it works good).

You can try it on Unity WebGL Player | Testing. I’m also leaving some screenshots of the project.

Hi @Atletadam

Please submit this project with a bug report. If it’s only happening on WebGL it’s likely to be an internal issue.

In the meantime as a workaround, I recommend you store the position when pausing and seek there when restarting.

Thanks,
Vincent

I had the same problem as you.

The solution was to store the time of the AudioSource.

Something like this:

//
    AudioSource audioSource;
    float currentTime;
    bool paused;

    void PlayPause()
    {
        paused = !paused;

        if (paused)
        {
            audioSource.Pause();
            currentTime = audioSource.time;
        }
        else
        {
            audioSource.time = currentTime;
            audioSource.Play();
        }
    }
//