(1) Chrome 66 policy change: default mute autoplay, need resume it

Modified files: lodeRunner.main.js, lodeRunner.misc.js
Cette révision appartient à :
SimonHung
2018-05-15 18:18:27 +08:00
Parent 3979b22b46
révision 0bfca18335
3 fichiers modifiés avec 30 ajouts et 1 suppressions
+1 -1
Voir le fichier
@@ -1,4 +1,4 @@
var VERSION = "2.21d"; var VERSION = "2.21g";
var AI_VERSION = 4; var AI_VERSION = 4;
var NO_OF_TILES_X = 28, var NO_OF_TILES_X = 28,
+2
Voir le fichier
@@ -204,6 +204,8 @@ function stopDemoAndPlay()
soundStop(soundFall); soundStop(soundFall);
stopAllSpriteObj(); stopAllSpriteObj();
resumeAudioContext(); //05/15/2018, chrome 66 default mute autoplay, need resume it
if(playMode == PLAY_DEMO || playMode == PLAY_DEMO_ONCE) selectIconObj.disable(1); if(playMode == PLAY_DEMO || playMode == PLAY_DEMO_ONCE) selectIconObj.disable(1);
if(playMode == PLAY_DEMO_ONCE) showStartMsg = 0; if(playMode == PLAY_DEMO_ONCE) showStartMsg = 0;
////genUserLevel(MAX_EDIT_LEVEL); //for debug only ////genUserLevel(MAX_EDIT_LEVEL); //for debug only
+27
Voir le fichier
@@ -277,3 +277,30 @@ function getDemoData(playData)
playerDemoData[wDemoData[i].level-1] = wDemoData[i]; playerDemoData[wDemoData[i].level-1] = wDemoData[i];
} }
} }
//===========================================================================
// Chrome 66 policy changes default mute autoplay, need resume it
// https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
//
// Reference: https://github.com/CreateJS/SoundJS/issues/297
//===========================================================================
function resumeAudioContext()
{
// handler for fixing suspended audio context in Chrome
//------------------------------------------------------------------
// Error Msgs:
// "The AudioContext was not allowed to start.
// It must be resume (or created) after a user gesture on the page.
// https://goo.gl/7K7WLu"
//------------------------------------------------------------------
try {
if (createjs.WebAudioPlugin.context.state === "suspended") {
createjs.WebAudioPlugin.context.resume();
console.log("Resume Web Audio context...");
}
} catch (e) {
// SoundJS context or web audio plugin may not exist
console.error("There was an error while trying to resume the SoundJS Web Audio context...");
console.error(e);
}
}