- Home /
Audio behaves accordingly in editor but not android
I have a gameObject in my scene that has an Audio Source which plays the main themes music. When I choose to switch off the audio in the editor, it does so accordingly, then when I switch it back on, again, it behaves the way it's supposed to.
The problem is, if I was to repeat this process on my android build, the music will constantly play, I can't get it to stop. This couldn't be any more frustrating so if anyone has any solutions for me, i'd greatly appreciate it.
Edit
mainMenu.cs#
void Start()
{
if (PlayerPrefs.GetInt("audio", optionsMenu.audio) == 1)
{
Camera.main.GetComponent<AudioListener>().enabled = true;
}
else if (PlayerPrefs.GetInt("audio", optionsMenu.audio) == 0)
{
Camera.main.GetComponent<AudioListener>().enabled = false;
}
}
optionsMenu.cs
void checkAudio() { if (noAudio.isOn == true) { audio = 0; PlayerPrefs.SetInt("audio", audio); yesAudio.isOn = false; }
else if (yesAudio.isOn == true)
{
audio = 1;
PlayerPrefs.SetInt("audio", audio);
noAudio.isOn = false;
}
else if (yesAudio.isOn == false && noAudio.isOn == false)
{
audio = 1;
PlayerPrefs.SetInt("audio", audio);
yesAudio.isOn = true;
}
}
This is the code I'm using, the options menu function is run in the update, I keep the players input in a player pref for later use, so then when the main menu is loaded, I have it checking to see what that value is.
Like I said, this all runs when I play it in Unity, just not on android :/
@brianruggieri I've updated my question, I disable the listener as I want all audio stopped
Hello,
When do you call checkAudio()?
Also your decision system seems very complicated for a very simple thing. Do you ever set noAudio.isOn to true?
Answer by Vunpac · Sep 25, 2014 at 06:59 AM
First - You can only have one AudioListener in a scene. That being said you are not required to get it like a component. You can just flat out use AudioListener.enabled.
Second - You can't use enabled with the AudioListener. You should be using AudioListener.pause.
Now depending on exactly what you want to do you may run into A LOT of buggy behavior. I have been messing about with it for quite some time, and came up with many workarounds. So just be aware you may run into a few more issues.
Your answer
![](https://koobas.hobune.stream/wayback/20220613163556im_/https://answers.unity.com/themes/thub/images/avi.jpg)