Audio un-pauses when game gets focus

I've implemented a pausing system (in javascript) that uses AudioListener.pause = true in order to temporarily stop all sounds that are currently playing. This works fine for the most part, but I've found that when switching to a different application, and then returning to the game, the audio will resume playing, even if the game is still in its "paused" state.

I've managed to limit this for the most part by checking if the game should be paused at the beginning of Update, and using AudioListener.pause again, if it should be. However, you still hear a split-second burst of audio before it pauses. It's not really enough to be noticeable, but if you switch out and in enough times, the audio stops synching up with its subtitles.

Has anybody else encountered this, or have an idea for how I could be pausing better, so my AudioListener stays paused?

bool hasFocus = true;

void OnApplicationFocus() {
    hasFocus != hasFocus;
    if (!hasFocus) AudioListener.pause = true; // Or whatever you do to pause
}

void Update() { 
    if (GameIsPaused) AudioListener.pause = true;
    else if (AudioListnener.pause) AudioListener.pause = false;
    else return;
}

JavaScript:

var hasFocus : bool = true;

function OnApplicationFocus() [
   hasFocus = != hasFocus;
   if (!hasFocus) AudioListner.pause = true; // Or whatever you do to pause
}

function Update() {
   if (GameIsPaused) AudioListner.pause = true;
   else if (AudioListner.pause) AudioListner.pause = false;
   else return;
}

Let me know if you need a JavaScript version