Search Unity

Chrome On The Dev Branch (version 66) May Block Audio For Unity WebGL

Discussion in 'Web' started by kognito1, Feb 15, 2018.

  1. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    So I fired up one of our applications today in chrome (version 66) and mysteriously there was no audio. The applications worked fine in other browsers and sites like youtube played audio fine in Chrome. So what gives? Well I checked the console and...

    chrome_blocking_audio.png

    That links to this page here: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes#webaudio

    I guess there's no way around this huh? This is probably "by design" according to Chrome. Is there a way that unity could let us "restart" the AudioContext as a callback to an event listener? I really don't know how we will get around this issue...
     
  2. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    1,073
    We can repro that inhouse and will take a look. Will post issue tracker link as soon as I get the number.
     
    MNNoxMortem likes this.
  3. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    598
    Do you have a workaround or a fixe ready for the 2018.x version?
    It look that chrome will release the version 66 in a week : https://www.chromestatus.com/features/schedule
    So what we do if the audio do not work?
    Thank you
     
    Last edited: Apr 9, 2018
  4. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    1,073
    There is currently no workaround, but we're still looking into it.
     
  5. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    598
    Like the google update is planned for the next week and that i doubt that like per magic you will release a patch for that, can you tell us if a workaround is possible on the Audio.js file present on Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib ?

    Thank you.
     
  6. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    1,073
  7. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    598
    Hello,

    Sorry, but this solution do not help.

    After a few test, it seem that :

    - If you click the page where the game is loading, then we do not get the warning message in the console and the audio should work.

    - If you do not click the page (just do not click the page or move your mouse till loading is complete), then we get the warning message in the console and the audio should not work.

    Tested on chrome canary 67.0.3394.0
    The both build do not contain any audio.

    Link with captureAllKeyboardInput set to true : http://www.asr-games.net/testing/BuildTrue/
    Link with captureAllKeyboardInput set to false : http://www.asr-games.net/testing/BuildFalse/

    The result is the same in the both build. It's maybe a window focus problem?
    If the user do not interact with the page where the game is loading, then chrome shut down the audio and we have no way to get it back (we have to refresh the page).

    Why you do not add a preloader (like on most video player or 3d viewer) that cover the content of the game and wait after a click on the game view in order to init the _JS_Sound_Init() (info here https://forum.unity.com/threads/uni...-but-stalls-on-chrome-66.525935/#post-3456219)

    For me, it's a critical issue as chrome is used by 80% of our players.

    This problem has been reported 2 months ago by kognito and we are at the same point. I'm sorry, but the unity team are doing something wrong somewhere in term of communication.

    The unity staff said working or been in contact with the google team but google have annouced this audio change in September 2017 and we are still talking about that.....

    Thank you
     
  8. Kognito

    Kognito

    Joined:
    Nov 21, 2014
    Posts:
    14
    We can confirm that the suggested workaround did not fix the problem for us, either. Is there some additional requirement?
     
  9. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    1,073
    There are no additional requirements for it. We are still looking into a solution but can't promise anything at this point.
     
  10. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    598
    Are you serious? I think that you need to stop drinking coffee and start working.

    You are a complet team working on the webgl stuff and no one of you are able to find a workaround before an internal fixe?

    It's an april fool or what???

    As simple hobbyist, it take me 2 hours yesterday to fixe this issue and nothing in 2 months for you??

    Can i generate an invoice to Unity because i have lost 2 hours with my wife and son because of some lazy guys?

    It's really unbelievable to see that, really crazy .....

    Sorry for this message, but that webgl story with unity start to piss me off.

    There you go ...... https://www.asr-games.net/testing/buildbutton

    Is that hard?
     
    dCalle likes this.
  11. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    First of all apologies for the inconvenience. This issue clearly fell through the cracks.
    Adding a button per-se is not hard but this is probably something you want to customize based on your content anyway. Ideally, you have your own WebGL template which implements such flow.

    Having said that we understand this is a problem, especially for first-time users, and we are going to provide a solution as soon as possible.
     
  12. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    could you try to the following?

    - make a development build
    - open the generated <buildname>.framework.unityweb
    - replace _JS_Sound_Init() with:
    Code (csharp):
    1. function _JS_Sound_Init() {
    2.   try {
    3.     window.AudioContext = window.AudioContext || window.webkitAudioContext;
    4.     WEBAudio.audioContext = new AudioContext();
    5.     var tryToResumeAudioContext = function() {
    6.       if (WEBAudio.audioContext.state === 'suspended')
    7.         WEBAudio.audioContext.resume();
    8.       else {
    9.         clearInterval(resumeInterval);
    10.       }
    11.     };
    12.     var resumeInterval = setInterval(tryToResumeAudioContext, 400);
    13.     WEBAudio.audioWebEnabled = 1;
    14.   } catch (e) {
    15.     alert("Web Audio API is not supported in this browser");
    16.   }
    17. }
    with the above code, audio should start as soon as the user interacts with the page. If that works you can patch your Unity installation by changing the source code in PlaybackEngines/WebGLSupport/BuildTools/lib/Audio.js

    Ideally, we should also display a message to the user.
     
    Last edited: May 8, 2018
  13. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    One more note, this workaround is an alternative to a playButton-style solution previously suggested, which we are also investigating.
     
  14. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331

    It works! A little brute force, but it works! :D
     
  15. game_apps

    game_apps

    Joined:
    Mar 3, 2016
    Posts:
    36
    Can we update the live games(non development) without needing to rebuild from unity? We have a lot of games with web license bought from the developers(ofc without source code), so wanted to know if we can have this workaround without the needing of extra "Play" button ahead. @Marco-Trivellato
     
  16. jura_z

    jura_z

    Unity Technologies

    Joined:
    Oct 10, 2016
    Posts:
    27
    Yes, you still can patch <buildname>.framework.unityweb. Non-dev version is minified version of the development one, so it's slightly harder to find that code.
     
  17. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    FYI the chrome release is now live. Thanks again @Marco-Trivellato for the workaround. Looking forward to seeing it in a patch release! :p
     
  18. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Thanks to @jura_z :)

    Yes, this will make it into a patch release in the next few weeks.
     
  19. Baraphor

    Baraphor

    Joined:
    Nov 16, 2016
    Posts:
    32
    Is this in a patch release yet?

    we are being overwhelmed with the number of support tickets coming in right now.
     
  20. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    No yet. We are finishing to work on a couple of other Chrome-WebAudio fixes. We will back-port them all together.

    In the meantime, you can patch your Audio.js file so you don't need to wait for us.
     
  21. game_apps

    game_apps

    Joined:
    Mar 3, 2016
    Posts:
    36
    We cant read that minified file, any way to read and make changes to this file ?
     
  22. jura_z

    jura_z

    Unity Technologies

    Joined:
    Oct 10, 2016
    Posts:
    27
    What do you mean exactly? You don't have access to it, or...?
     
  23. Martian-Games

    Martian-Games

    Joined:
    Jan 19, 2012
    Posts:
    44
    I think he means that, yeah, indeed this minified code is difficult to read once built: ;) [EXAMPLE]....

    ‹Ò(ìZ AudioLinkTest.asm.framework.unityweb UnityWeb Compressed Content (gzip) Ìi{½ñ{Ù¶.Öð²Éc;NêÖv\oÚº”gµ½ °”]|ÓßÞ9tí…ÁMû´oc´Òh4’F£Ñh$•¯§£^„£òqØŸ|»4û‡®¬ñÄ?›Ž¬vu<nËÒžÝy“ÒtďŸƒþÅþð>]™3'Íj?=™(‚ëò+¯£¾ÿà÷?íÙ³^8ŠBˆ„7eëPÆ—‚¨4
    ã’wç¯é¥O^ì•îƒÁ€Æþ$
    ¢¸ŒJ=¯wë—¼Q¿t:ðýÉéÄ¿Ž4d×/Eޝ߯Zöüóyuø£LÊÖ› ß½Ž,»…Qát—?í}>wfsG§ j½~Zå“?ö¼Qï±lýá¼£ëÚ9ÆüŒ*zõ®£r<™úŽ®»?™Ø3lâÃ;|sþßÊiØ2&µdËŸûñçé`õ&¾]çêb¯U45~ü8öÃëҐCÞ ø§ßw]ך)×ÁÈï[OO¯² ©~:c jß@C•ý›ÙD~I—
     
  24. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    @game_apps @Martian-Games try:
    • change the file extension to .zip
    • unzip it, then it should be quite readable (uncompressed, minified)
    • make the change
    • zip it
    • change the extension back to .unityweb
     
    Last edited: May 4, 2018
    LilGames and game_apps like this.
  25. 8volution

    8volution

    Joined:
    Nov 14, 2012
    Posts:
    88
    On windows, trying to unzip the file after changing the extension returns an 'invalid file' error.
     
  26. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    1,073
    Try using 7-zip.
     
  27. 8volution

    8volution

    Joined:
    Nov 14, 2012
    Posts:
    88
    Thanks, that worked! Just had to compress back to gzip using 7-zip for it to work.
     
  28. game_apps

    game_apps

    Joined:
    Mar 3, 2016
    Posts:
    36
    Thanks
     
  29. TheOz

    TheOz

    Joined:
    May 21, 2011
    Posts:
    34
    @Marco-Trivellato , just made the patch myself. Thanks. I had been chasing the mobile safari audio mute issue and though I had killed chrome audio! I have a suggestion. for WebGL builds make the button part of the splash screen, either the unity3d one or the custom. for now I think im going to add a click event to the JS_Sound_Init and handle the mobile safari audio issue there as well.

    Keep up the good work.

    Garry
     
  30. TheOz

    TheOz

    Joined:
    May 21, 2011
    Posts:
    34
    @Marco-Trivellato , The replacement to JS_Sound_Init as you described installed fine. I had to change the permissions down the Unity path to allow for the file to be saved after the change. no biggie. Works great on Chrome in windows and Android.

    However, now when playing it in Safari (desktop mac) or mobile safari (Iphone 6) I just get a grey screen after clicking the ok warning message and unity loading shows. It just hangs there on a grey screen.

    Any ideas?


    Garry
     
  31. Jinxology

    Jinxology

    Joined:
    Jul 13, 2013
    Posts:
    95
    I keep getting a "SyntaxError: illegal character" javascript error after I re-compress and replace the *.framwork.unityweb file . It decompresses just fine, but even if I decompress it, make no changes to the file, and re-compress it, I get this error. What settings do I need to use in 7-zip when compressing?
     
  32. dradb

    dradb

    Joined:
    Jan 10, 2015
    Posts:
    86
    Marco, I have commented in another thread, but I am meeting clients on Wednesday and I am anxious. I have a main app and 3 modules of it as a separate demo. Chrome was not playing audio in either app. I added your fix and the main app is now working, however the demo crashes at the first user interaction ... in Chrome AND in Firefox.

    Uncaught abort(-1) at Error
    at jsStackTrace (blob:http://www.q-skills.com/751db6a5-30d5-4f2d-8883-5df63331fbe5:1:22814)
    at stackTrace (blob:http://www.q-skills.com/751db6a5-30d5-4f2d-8883-5df63331fbe5:1:22997)
    at abort (blob:http://www.q-skills.com/751db6a5-30d5-4f2d-8883-5df63331fbe5:36:53511)
    at _JS_Sound_ReleaseInstance (blob:http://www.q-skills.com/751db6a5-30d5-4f2d-8883-5df63331fbe5:1:198345)
    at lTc (blob:http://www.q-skills.com/751db6a5-30d5-4f2d-8883-5df63331fbe5:25:95273)
    at qVc (blob:http://www.q-skills.com/751db6a5-30d5-4f2d-8883-5df63331fbe5:25:128809)
    at cRc (blob:http://www.q-skills.com/751db6a5-30d5-4f2d-8883-5df63331fbe5:25:57758)
    at CRc (blob:http://www.q-skills.com/751db6a5-30d5-4f2d-8883-5df63331fbe5:25:78148)
    at GMc (blob:http://www.q-skills.com/751db6a5-30d5-4f2d-8883-5df63331fbe5:10:955129)
    at $Ra (blob:http://www.q-skills.com/751db6a5-30d5-4f2d-8883-5df63331fbe5:23:334011)
    If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information."

    I'm using 5.3.2 Help please.
     
    Last edited: May 6, 2018
  33. TheOz

    TheOz

    Joined:
    May 21, 2011
    Posts:
    34
    Hi Dradb, are you using the unzip, update JS_SOUND_INIT and rezip technique?
     
  34. dradb

    dradb

    Joined:
    Jan 10, 2015
    Posts:
    86
    Thank you for your reply.
    No. I just edited PlaybackEngines/WebGLSupport/BuildTools/lib/Audio.js using Marco's code and rebuilt the WebGL files.
     
  35. dradb

    dradb

    Joined:
    Jan 10, 2015
    Posts:
    86
    Here's the js console from the Firefox crash. What is the missing "JS_Sound_ReleaseInstance" ?

    UnloadTime: 2.000000 ms UnityLoader.js:1
    Unloading 5 Unused Serialized files (Serialized files now loaded: 0) UnityLoader.js:1
    missing function: JS_Sound_ReleaseInstance UnityLoader.js:1
    -1 UnityLoader.js:1
    -1 UnityLoader.js:1
    Invoking error handler due to
    uncaught exception: abort(-1) at jsStackTrace@blob:http://www.q-skills.com/87dc9580-904a-4698-9e12-a7570aebef73:1:22814
    stackTrace@blob:http://www.q-skills.com/87dc9580-904a-4698-9e12-a7570aebef73:1:22997
    abort@blob:http://www.q-skills.com/87dc9580-904a-4698-9e12-a7570aebef73:36:53511
    _JS_Sound_ReleaseInstance@blob:http://www.q-skills.com/87dc9580-904a-4698-9e12-a7570aebef73:1:198346
     
  36. Jinxology

    Jinxology

    Joined:
    Jul 13, 2013
    Posts:
    95
    Just to clarify a few things, you don't actually need to unzip the framework.unityweb file if you make a Development build, it won't be compressed or minified. If you choose to just edit the source file (PlaybackEngines/WebGLSupport/BuildTools/lib/Audio.js), that is also non-compressed or minified. Both of these solutions worked for me, thanks @Marco-Trivellato
     
  37. dradb

    dradb

    Joined:
    Jan 10, 2015
    Posts:
    86
    What I can't understand is that it seems to work OK for my full app but not the demo. The demo just has a few modules of the full app. I've been playing around cutting bits out but the demo version keeps crashing.
     
  38. ChristianKoGaMa

    ChristianKoGaMa

    Joined:
    Jul 11, 2017
    Posts:
    18
    Hi,
    I think I might be seeing the same issue in latest version of Firefox. Can anybody confirm if this is the case?
     
  39. dradb

    dradb

    Joined:
    Jan 10, 2015
    Posts:
    86
    It looks like line 4 should be:

    WEBAudio.audioContext = new AudioContext();

    ... but it still doesn't stop the crash, related to "JS_Sound_ReleaseInstance", whatever and where ever that is ??
     
  40. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    598
    First return to the original file to see if everything come back to normal and then move foward step by step.
     
  41. Erik-Sombroek

    Erik-Sombroek

    Joined:
    Jul 21, 2015
    Posts:
    10
    I have exactly this issue! Is there a way to avoid having to get a development build? We have many projects from clients all with no dev builds. Have to reach out to those partners and QA-ing all the games again is going to be a pain. (We have an online web portal). Is there a way i can make this work with a non-dev build? I have done exactly what is told, but i get the
    Invoking error handler due to SyntaxError: Invalid character '\u001f' Error
     
  42. NightOwlGamingLLC

    NightOwlGamingLLC

    Joined:
    Jun 14, 2014
    Posts:
    9
    This fixed the issue for me completely, thank you very much Marco !!
     
  43. dradb

    dradb

    Joined:
    Jan 10, 2015
    Posts:
    86
    Thanks roka. After wasting a dew days, you have by far the simplest and most reliable approach.
     
  44. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    could you please post a development build callstack?
     
  45. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Yes, thanks for pointing that out.

    I fixed my initial post.
     
  46. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    do you have any more detail on this? anything in the browser log?
     
  47. Erik-Sombroek

    Erik-Sombroek

    Joined:
    Jul 21, 2015
    Posts:
    10
  48. Erik-Sombroek

    Erik-Sombroek

    Joined:
    Jul 21, 2015
    Posts:
    10
    After tinkering with it for some more, i noticed that my gzip output on MAX compression still does not match the filesize of the unity gzipped version. Are you stripping even more content from the gzip?
     
  49. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Could you add any context information? Where do you get this error?
    Assuming it's when loading in the browser, are you able to get the build to load locally (without uploading to a server)?
     
  50. Erik-Sombroek

    Erik-Sombroek

    Joined:
    Jul 21, 2015
    Posts:
    10
    Hey Marco, so what im doing is - using a production build, unzipping the <game>.asm.framework, altering the code, and then running 'gzip --keep --no-name --best TunnelRushWebGL.asm.framework' in my terminal. After uploading this build online the application crashes on that specific character ''\u001f''.

    Even when i just gunzip and gzip the file without altering anything i get the same crash. It seems that you either have a different gzip, or use different settings because i notice you get a 78.5% compression rate where i can only max get a 78% compression rate. (your gzip results in a 91kb file, and mine in a 93kb file)