Bug in AudioListener: AL_Invalid_Value

I think I have found a bug in the AudioListener that gives an error when I use the pause function. I will prepare a bug report and hope it is fixed in the next version, but before then I was hoping someone might have encountered it or be able to suggest a workaround.

The error happens consistently on the iPhone and occasionally in the Editor, when I use AudioListener.pause. In the editor I receive the error: AL_Invalid_Value, sometimes specifying an AudioSource. This code produces it sometimes:

function PauseGame(){
    	AudioListener.pause = true;
    	savedTimeScale = Time.timeScale; //Save timescale to be restored later
    	Time.timeScale = 0;
    	...
}

and in this code it happens when I move from the main scene to another scene if a sound was playing before pausing:

function OnLevelWasLoaded(){
    Time.timeScale = 1;
    AudioListener.pause = false;
    enabled=false;
}

I know it is the AudioListener causing the problem because if I comment out those lines the crashes stop, and when no sound files were present there were also no crashes.

I have tried making sure the AudioListener is always unpaused before changing scenes, or changing the timescale, but that did not help. There is always 1 Listener in the scene. Does this make sense to anyone?

I have just hit that issue with unity iphone 1.7 after trying to implement a mute button with AudioListener.pause

Not fixed then I guess…

says Assert in file: … /Runtime/Audio/AudioManager.cpp at line: 346

Edit: The workaround is AudioListener.volume = 0/1

I faced it at Unity 1.7 randomly not consistently.

I got around this by avoiding the AudioListener.pause function. You could set the volume to 0, but I was using the function to pause the game, and there was a specific object where I wanted the sound to be properly paused so it would start off from the same place when the game was resumed. So inside PauseGame() I added code to find this object (slightly messy but it works) and pause the AudioSource on that GameObject, then set volume to 0 to simply mute all other sounds. It was great to see the random crashes finally stop!

You could also try pausing all AudioSources using FindObjectsOfType(AudioSource), or another way that wouldn’t be so slow.