Problems with audio not launching in webgl build

Hi everyone, I followed this link to check what was wrong, as my build does not load with the sound it should load.
So here the message I got:

BlockquoteSleepWalker.framework.js:3368 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
_JS_Sound_Init @ SleepWalker.framework.js:3368
SleepWalker.framework.js:3370 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu

The way I understandd this, is that the default settings for the playerprefs haven’t been created.
I have no idea how to fix this
I appreciate any help
cheers
Patricia

Hi Patricia,

Did you upload your game? If so, could you share a link to it? Ideally, it should be the development build, so I hopefully can spot a few helpful error messages in my browser console.

Are there any error messages in your console in Unity when you run the game? Could there be a reference to an AudioSource missing?

Hi Nina,
no, no messages of any sort in the console.
I have not uploaded the game yet, as I was only checking if everything was alright

After reading many posts on here and on the web, I am unfortunately not wiser. I think I blocked on this one. I am positive though, that the issue is that a default volume value on first time launch isn’t set up. I have tried everything I thought could solve the problem, but nothing.
I “played” quite some glitch garden versions again and to my surprise, the majority didn’t have the sound set up, first time you started the game, which is a pity.
Last thing I’ve tried is this:
PlayerPrefsController:

const string INITIAL_VOLUME_KEY = "initial volume";

    public static void SetInitialVolume(float volume)
    {
        PlayerPrefs.SetFloat(INITIAL_VOLUME_KEY, volume);
        Debug.Log("initial volume set to " + volume);
    }

    public static float GetInitialVolume()
    {
        return PlayerPrefs.GetFloat(INITIAL_VOLUME_KEY, 1f);
    }

OptionController:

public void Awake()
    {
        if (!PlayerPrefs.HasKey("sfx volume")) PlayerPrefs.GetFloat("initial volume", 0.5f);
        if (!PlayerPrefs.HasKey("music volume")) PlayerPrefs.GetFloat("initial volume", 0.7f);
    }

As always, any help is highly appreciated

Theoretically, PlayerPrefs.GetFloat(INITIAL_VOLUME_KEY, 1f); should have worked. According to the API, the default value (the second argument) gets returned when the key was not found in the PlayerPrefs.

I’m relatively sure that the issue is not here but where the code tries to access the AudioSource. Or the problem is just related to the browser. Did you test your game in a different browser? Maybe you’ll have to allow the tab to play the sound on sharemygame.com. Test another student’s game on that website to see if you get the same problem.

Which version of Unity do you use, by the way? I’ve just stumbled upon this bug.

Hi Nina,
I agree with you that the AudioSource is not accessed right away. Well, that is my hunch anyways, because if I reset the playerprefs in my game, it does load with the first sound (not linked with the playerprefs), but not with the music or sound to it. Both sliders are at zero.
I am using unity 2020.1.9f1
I have just tested it again and the message is as the first time I’ve tested it:

SleepWalker.framework.js:3370 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu

I found the kickoff to the solution in this post. One thing is still not perfect, but I can live with the way it is now.
@Nina, thank you again for your support

I’m glad you found a solution. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms