From 3b4cc0434be2008cf70fd3e5bae7e2c75f5bd420 Mon Sep 17 00:00:00 2001 From: XProger Date: Sat, 16 Sep 2017 04:03:53 +0300 Subject: [PATCH] #15 WebGL fix audio for iOS browsers --- src/platform/web/index.html | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/platform/web/index.html b/src/platform/web/index.html index 6009086..670b7e3 100644 --- a/src/platform/web/index.html +++ b/src/platform/web/index.html @@ -66,15 +66,17 @@ }, }; + var audioContext = null; + function snd_init() { var AudioContext = window.AudioContext || window.webkitAudioContext; if (!AudioContext) return; - var ctx = new (window.AudioContext || window.webkitAudioContext)(); + audioContext = new (window.AudioContext || window.webkitAudioContext)(); var count = 2048; - var rate = 44100 / ctx.sampleRate; + var rate = 44100 / audioContext.sampleRate; var framesCount = Math.ceil(count * rate); var frames = Module._malloc(framesCount * 4); // interleaved short L, R - proc = ctx.createScriptProcessor(count, 2, 2); + proc = audioContext.createScriptProcessor(count, 2, 2); proc.onaudioprocess = function(e) { var L = e.outputBuffer.getChannelData(0), R = e.outputBuffer.getChannelData(1); @@ -85,9 +87,18 @@ R[i] = Module.getValue(index + 2, 'i16') / 0x8000; } } - proc.connect(ctx.destination); + proc.connect(audioContext.destination); } + // for iOS to unlock audio context after user interaction + var userAction = function() { + if (audioContext) { + audioContext.resume(); + window.removeEventListener('touchstart', userAction, false); + } + }; + window.addEventListener('touchstart', userAction, false); + var gl = canvasElement.getContext("webgl", {antialias:false, premultipliedAlpha: false}) || canvasElement.getContext("experimental-webgl", {antialias:false, premultipliedAlpha: false}); Module.setStatus('Downloading...'); @@ -106,7 +117,7 @@ (.PHD, .PSX)

OpenLara on github & facebook
-
last update: 14.09.2017
+
last update: 16.09.2017