I have a game that plays looping music using AudioSource.PlayScheduled. Browsers won’t let HTML games play audio until the user clicks on the game window. When the user clicks outside the window, audio pauses until the user clicks in the window again. Unfortunately, AudioSource.PlayScheduled doesn’t account for this pause, causing the scheduled clip to play early, which results in two copies of the music track playing over each other until the first audio source reaches the end of the clip. Then, after end of the second clip, there is a long gap of silence.
Is there some way for me to 1) detect when the game loses focus and 2) account for the audio pause so the scheduled playback stays in sync?
In case it helps, I have included my music player code.
Unity version is 2021.3.14.
9005215–1259128–MusicPlayer2.cs (11.2 KB)