threedollarbill Posted May 3, 2018 Share Posted May 3, 2018 Hi, the sound on my games suddenly cannot be heard. I'm not sure what's going on. When I look at the console (Chrome), it shows a message saying "The AudioContext was not allowed to start. It must be resume (or created) after a user gesture on the page.". Does anybody have an idea of what's going on? How can I get the sounds play again? BdR and fredMer 2 Link to comment Share on other sites More sharing options...
threedollarbill Posted May 3, 2018 Author Share Posted May 3, 2018 Ok I was able to fix it. For anyone wondering, this is what I did: this.game.input.onDown.addOnce(() => { this.game.sound.context.resume(); }); Phaser911, Zampano and BdR 3 Link to comment Share on other sites More sharing options...
samme Posted May 4, 2018 Share Posted May 4, 2018 Phaser CE tries to do this automatically. What version is yours? Link to comment Share on other sites More sharing options...
threedollarbill Posted May 4, 2018 Author Share Posted May 4, 2018 2 hours ago, samme said: Phaser CE tries to do this automatically. What version is yours? I'm currently using 2.9.4.. Looks like 2.10.3 is out. Does that version handle the audiocontext issue? Link to comment Share on other sites More sharing options...
Osric Posted May 4, 2018 Share Posted May 4, 2018 With Phaser CE 2.10.3 and the latest chrome release, this is still happening with our game ( I did look through the source code from that version, and it looked a lot like this was supposed to be handled automatically ). Link to comment Share on other sites More sharing options...
samme Posted May 4, 2018 Share Posted May 4, 2018 It does still a require a click on the canvas, though. Phaser can't stop the browser from suspending the context in the first place. Link to comment Share on other sites More sharing options...
Phaser911 Posted May 5, 2018 Share Posted May 5, 2018 @threedollarbill Thanks for the solution, so I need to update all games now? Link to comment Share on other sites More sharing options...
samme Posted May 5, 2018 Share Posted May 5, 2018 On 5/3/2018 at 8:31 PM, threedollarbill said: I'm currently using 2.9.4.. Looks like 2.10.3 is out. Does that version handle the audiocontext issue? Since v2.10.2 it does. Link to comment Share on other sites More sharing options...
threedollarbill Posted May 7, 2018 Author Share Posted May 7, 2018 @samme: Thank you! @Phaser911: If you're still using an older version of Phaser you should.. Link to comment Share on other sites More sharing options...
threedollarbill Posted May 7, 2018 Author Share Posted May 7, 2018 Actually, i just tested 2.10.4 now and it doesn't seem to handle the audiocontext issue. I still get no sound despite clicking on the canvas. Link to comment Share on other sites More sharing options...
samme Posted May 7, 2018 Share Posted May 7, 2018 4 hours ago, threedollarbill said: Actually, i just tested 2.10.4 now and it doesn't seem to handle the audiocontext issue. I still get no sound despite clicking on the canvas. Check the console? There's actually a flaw in Phaser's method. If it fails you'll see a second warning traced to resumeWebAudio. Link to comment Share on other sites More sharing options...
ForgeableSum Posted May 9, 2018 Share Posted May 9, 2018 With jQuery: $('html,body').on('click', function() { if (!inGame) { if (game != undefined) { game.sound.context.resume(); } } }); Link to comment Share on other sites More sharing options...
Zampano Posted May 9, 2018 Share Posted May 9, 2018 Thanks for posting your solution, I'm having the same problem despite using phaser 2.10.4. However, I am using multiple states for my game and I'm not sure where to put the code. In every state? Link to comment Share on other sites More sharing options...
ForgeableSum Posted May 9, 2018 Share Posted May 9, 2018 Do what I did: don't put it in a state, or in a game input event at all. Simply attach it to a click event on the body or html elements using jQuery. you know the user is going to click body or html eventually. Sucks that i can no longer auto-play intro music. On the other hand, I completely understand why Google implemented this as spammers take advantage of auto-play. Link to comment Share on other sites More sharing options...
samme Posted May 9, 2018 Share Posted May 9, 2018 8 hours ago, Zampano said: Thanks for posting your solution, I'm having the same problem despite using phaser 2.10.4. Check whether the audio context is still suspended (game.debug.sound shows this). Phaser v2.10.5 fixed a flaw in this process also. BdR 1 Link to comment Share on other sites More sharing options...
BdR Posted May 9, 2018 Share Posted May 9, 2018 6 hours ago, samme said: Check whether the audio context is still suspended (game.debug.sound shows this). Phaser v2.10.5 fixed a flaw in this process also. One of my games was using older version of the Phaser2 library, and simply replacing it with the latest v2.10.5 version fixed it Didn't even have to change my game script. samme 1 Link to comment Share on other sites More sharing options...
Nygaming Posted May 10, 2018 Share Posted May 10, 2018 Is there a way to do this in html5 code? Link to comment Share on other sites More sharing options...
Phaser911 Posted June 6, 2018 Share Posted June 6, 2018 So I have updated some games successfuly, but I realised other games still do not play audio on Android. Actually everything works fine if you visit the game directly, but if you embed the game in iframe, it does not work. I use this code by threedollarbill game.input.onDown.addOnce(() => { game.sound.context.resume(); }); I don't see any reason for this? Any ideas? If I use Phaser v2.10.5 , it works but the game is too slow. If I just replace phaser.min.js, the game is definately much slower on mobile. I expected the new version to be better than previous versions... Link to comment Share on other sites More sharing options...
Phaser911 Posted June 6, 2018 Share Posted June 6, 2018 Hm... if I use one older version of Phaser, everything works fine. Link to comment Share on other sites More sharing options...
d4rkd0s Posted February 1, 2020 Share Posted February 1, 2020 On 5/8/2018 at 11:27 PM, feudalwars said: With jQuery: $('html,body').on('click', function() { if (!inGame) { if (game != undefined) { game.sound.context.resume(); } } }); Where does `inGame` come from? Otherwise with this code as it stands this is what's produced:Uncaught ReferenceError: inGame is not defined Link to comment Share on other sites More sharing options...
Recommended Posts