MCPcopy
hub / github.com/goldfire/howler.js / setupAudioContext

Function setupAudioContext

src/howler.core.js:2512–2557  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2510 * Setup the audio context when available, or switch to HTML5 Audio mode.
2511 */
2512 var setupAudioContext = function() {
2513 // If we have already detected that Web Audio isn't supported, don't run this step again.
2514 if (!Howler.usingWebAudio) {
2515 return;
2516 }
2517
2518 // Check if we are using Web Audio and setup the AudioContext if we are.
2519 try {
2520 if (typeof AudioContext !== 'undefined') {
2521 Howler.ctx = new AudioContext();
2522 } else if (typeof webkitAudioContext !== 'undefined') {
2523 Howler.ctx = new webkitAudioContext();
2524 } else {
2525 Howler.usingWebAudio = false;
2526 }
2527 } catch(e) {
2528 Howler.usingWebAudio = false;
2529 }
2530
2531 // If the audio context creation still failed, set using web audio to false.
2532 if (!Howler.ctx) {
2533 Howler.usingWebAudio = false;
2534 }
2535
2536 // Check if a webview is being used on iOS8 or earlier (rather than the browser).
2537 // If it is, disable Web Audio as it causes crashing.
2538 var iOS = (/iP(hone|od|ad)/.test(Howler._navigator && Howler._navigator.platform));
2539 var appVersion = Howler._navigator && Howler._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
2540 var version = appVersion ? parseInt(appVersion[1], 10) : null;
2541 if (iOS && version && version < 9) {
2542 var safari = /safari/.test(Howler._navigator && Howler._navigator.userAgent.toLowerCase());
2543 if (Howler._navigator && !safari) {
2544 Howler.usingWebAudio = false;
2545 }
2546 }
2547
2548 // Create and expose the master GainNode when using Web Audio (useful for plugins or advanced usage).
2549 if (Howler.usingWebAudio) {
2550 Howler.masterGain = (typeof Howler.ctx.createGain === 'undefined') ? Howler.ctx.createGainNode() : Howler.ctx.createGain();
2551 Howler.masterGain.gain.setValueAtTime(Howler._muted ? 0 : Howler._volume, Howler.ctx.currentTime);
2552 Howler.masterGain.connect(Howler.ctx.destination);
2553 }
2554
2555 // Re-run the setup on Howler.
2556 Howler._setup();
2557 };
2558
2559 // Add support for AMD (Asynchronous Module Definition) libraries such as require.js.
2560 if (typeof define === 'function' && define.amd) {

Callers 1

howler.core.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected