(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
+27
Voir le fichier
@@ -277,3 +277,30 @@ function getDemoData(playData)
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);
}
}