Simple-Unity-Audio-Manager icon indicating copy to clipboard operation
Simple-Unity-Audio-Manager copied to clipboard

Channel helper gets disabled when unity loses focus

Open MadScientist11 opened this issue 2 years ago • 1 comments

Hi! So while I was trying to control audio with timescale, I noticed what seems to be a bug.

Issue - When unity loses focus, e.g I alt-tab to browser, channel helper gets disabled and I can't control the audio with timescale. It happens when audio file is set as non-looping. I noticed that BaseAudioChannelHelper for non-looping files has this check in update:

if (audioFile.loopMode == LoopMode.NoLooping)
{
   // Disable self if not playing anymore
   enabled = AudioSource.isPlaying;
}

It seems that AudioSource.isPlaying is returning false after unity gets unfocused, so the component gets disabled. My workaround for this is enabling the script back after returning to Unity. Seems to work fine.

private void OnApplicationPause(bool pauseState)
{
    if (!pauseState)
    {
        if (_bgmChannelHelper.AudioSource.isPlaying)
        {
            _bgmChannelHelper.enabled = true;
        }
    }
}

MadScientist11 avatar Jan 02 '24 20:01 MadScientist11

Thanks for reporting the issue, you are correct in assuming this is a bug.

This issue will be fixed in the next update. In the meantime, your workaround shouldn't affect the rest of JSAM's behaviour. 👍

jackyyang09 avatar Jan 05 '24 01:01 jackyyang09