The AudioContext was not allowed to start

The AudioContext was not allowed to start
0

i played my bgm on game scene.
it played on script ( update method )

if i play the game at new windows it work!
(run game on chrome browser by cc’s [:arrow_forward:] button)

but if i refresh on chrome browser, it’s not work and it’s said it!

The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.
not work : (refresh game on chrome browser by cc’s Refresh button or refresh on chrome) but sometime it’s work

@property(cc.AudioSource) au_start: cc.AudioSource = null;
@property(cc.AudioSource) au_bgm: cc.AudioSource = null;

public gameState = 0;
public runTime = 0;

update(dt:number) : void{
       if(this.gameState == 0){
              this.au_start.play();
              this.gameState = 1;
       }else if(this.gameState == 1){
              if(runTime > 3) this.gameState =2;
       }else if(this.gameState == 2){
              this.au_bgm.play();
              this.gameState = 3;
       }

       runTime += dt;
}

What’s mean about User Gesture?
what can i do for this problem?

--------------- error message -------------
CCSys.js:1059 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
(anonymous) @ CCSys.js:1059
newRequire @ browserify_prelude.js:38
(anonymous) @ browserify_prelude.js:39
(anonymous) @ CCPath.js:29
newRequire @ browserify_prelude.js:38
(anonymous) @ browserify_prelude.js:39
(anonymous) @ index.js:29
newRequire @ browserify_prelude.js:38
(anonymous) @ browserify_prelude.js:39
(anonymous) @ predefine.js:32
newRequire @ browserify_prelude.js:38
(anonymous) @ browserify_prelude.js:39
(anonymous) @ index.js:57
newRequire @ browserify_prelude.js:38
outer @ browserify_prelude.js:44
(anonymous) @ browserify_prelude.js:12
CCAudio.js:378 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
22.proto.play @ CCAudio.js:378
22.proto.play @ CCAudio.js:145
play @ CCAudioSource.js:263
GameScene.run @ GameScene.ts:90
DefaultScene.update @ DefaultScene.ts:72
(anonymous) @ VM4308:3
invoke @ component-scheduler.js:203
updatePhase @ component-scheduler.js:466
mainLoop @ CCDirector.js:1473
callback @ CCGame.js:582
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
CCAudio.js:370 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
22.proto.play @ CCAudio.js:370
22.proto.play @ CCAudio.js:145
play @ CCAudioSource.js:263
GameScene.run @ GameScene.ts:104
DefaultScene.update @ DefaultScene.ts:72
(anonymous) @ VM4308:3
invoke @ component-scheduler.js:203
updatePhase @ component-scheduler.js:466
mainLoop @ CCDirector.js:1473
callback @ CCGame.js:582
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
requestAnimationFrame (async)
callback @ CCGame.js:576
CCAudio.js:370 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
22.proto.play @ CCAudio.js:370
22.proto.resume @ CCAudio.js:183
_restoreCallback @ CCAudioSource.js:216
113.EventListeners.invoke @ event-listeners.js:49
114.proto.emit @ event-target.js:444
onShown @ CCGame.js:784
(anonymous) @ CCGame.js:804
CCAudio.js:378 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
22.proto.play @ CCAudio.js:378
22.proto.resume @ CCAudio.js:183
_restoreCallback @ CCAudioSource.js:216
113.EventListeners.invoke @ event-listeners.js:49
114.proto.emit @ event-target.js:444
onShown @ CCGame.js:784
(anonymous) @ CCGame.js:804
CCAudio.js:370 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
22.proto.play @ CCAudio.js:370
22.proto.resume @ CCAudio.js:183
_restoreCallback @ CCAudioSource.js:216
113.EventListeners.invoke @ event-listeners.js:49
114.proto.emit @ event-target.js:444
onShown @ CCGame.js:784
(anonymous) @ CCGame.js:804
CCAudio.js:378 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
22.proto.play @ CCAudio.js:378
22.proto.resume @ CCAudio.js:183
_restoreCallback @ CCAudioSource.js:216
113.EventListeners.invoke @ event-listeners.js:49
114.proto.emit @ event-target.js:444
onShown @ CCGame.js:784
(anonymous) @ CCGame.js:804
CCAudio.js:370 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
22.proto.play @ CCAudio.js:370
22.proto.resume @ CCAudio.js:183
_restoreCallback @ CCAudioSource.js:216
113.EventListeners.invoke @ event-listeners.js:49
114.proto.emit @ event-target.js:444
onShown @ CCGame.js:784
(anonymous) @ CCGame.js:804
CCAudio.js:378 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu

Actually it’s a browser issue.
Some browser including chrome don’t allow to play music by default.

There are some ways to handle this issue, one of which is you can add “Touch to continue” kind of message before main screen.

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