From e9b7e8cd5633cfd9be2cacac3a894ddea845e9e2 Mon Sep 17 00:00:00 2001 From: James Simpson Date: Fri, 30 Mar 2018 16:51:08 -0500 Subject: [PATCH] Fix another deprecation warning in Chrome Fixes #923 --- src/plugins/howler.spatial.js | 45 ++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/plugins/howler.spatial.js b/src/plugins/howler.spatial.js index 9573ad64..308b2ac8 100644 --- a/src/plugins/howler.spatial.js +++ b/src/plugins/howler.spatial.js @@ -17,7 +17,7 @@ // Setup default properties. HowlerGlobal.prototype._pos = [0, 0, 0]; HowlerGlobal.prototype._orientation = [0, 0, -1, 0, 1, 0]; - + /** Global Methods **/ /***************************************************************************/ @@ -65,7 +65,14 @@ if (typeof x === 'number') { self._pos = [x, y, z]; - self.ctx.listener.setPosition(self._pos[0], self._pos[1], self._pos[2]); + + if (typeof self.ctx.listener.positionX !== 'undefined') { + self.ctx.listener.positionX.setTargetAtTime(self._pos[0], Howler.ctx.currentTime, 0.1); + self.ctx.listener.positionY.setTargetAtTime(self._pos[1], Howler.ctx.currentTime, 0.1); + self.ctx.listener.positionZ.setTargetAtTime(self._pos[2], Howler.ctx.currentTime, 0.1); + } else { + self.ctx.listener.setPosition(self._pos[0], self._pos[1], self._pos[2]); + } } else { return self._pos; } @@ -105,7 +112,17 @@ if (typeof x === 'number') { self._orientation = [x, y, z, xUp, yUp, zUp]; - self.ctx.listener.setOrientation(x, y, z, xUp, yUp, zUp); + + if (typeof self.ctx.listener.forwardX !== 'undefined') { + self.ctx.listener.forwardX.setTargetAtTime(x, Howler.ctx.currentTime, 0.1); + self.ctx.listener.forwardY.setTargetAtTime(y, Howler.ctx.currentTime, 0.1); + self.ctx.listener.forwardZ.setTargetAtTime(z, Howler.ctx.currentTime, 0.1); + self.ctx.listener.upX.setTargetAtTime(x, Howler.ctx.currentTime, 0.1); + self.ctx.listener.upY.setTargetAtTime(y, Howler.ctx.currentTime, 0.1); + self.ctx.listener.upZ.setTargetAtTime(z, Howler.ctx.currentTime, 0.1); + } else { + self.ctx.listener.setOrientation(x, y, z, xUp, yUp, zUp); + } } else { return or; } @@ -211,7 +228,9 @@ } if (pannerType === 'spatial') { - sound._panner.setPosition(pan, 0, 0); + sound._panner.positionX.setValueAtTime(pan, Howler.ctx.currentTime); + sound._panner.positionY.setValueAtTime(0, Howler.ctx.currentTime); + sound._panner.positionZ.setValueAtTime(0, Howler.ctx.currentTime); } else { sound._panner.pan.setValueAtTime(pan, Howler.ctx.currentTime); } @@ -285,7 +304,9 @@ setupPanner(sound, 'spatial'); } - sound._panner.setPosition(x, y, z); + sound._panner.positionX.setValueAtTime(x, Howler.ctx.currentTime); + sound._panner.positionY.setValueAtTime(y, Howler.ctx.currentTime); + sound._panner.positionZ.setValueAtTime(z, Howler.ctx.currentTime); } self._emit('pos', sound._id); @@ -363,7 +384,9 @@ setupPanner(sound, 'spatial'); } - sound._panner.setOrientation(x, y, z); + sound._panner.orientationX.setValueAtTime(x, Howler.ctx.currentTime); + sound._panner.orientationY.setValueAtTime(y, Howler.ctx.currentTime); + sound._panner.orientationZ.setValueAtTime(z, Howler.ctx.currentTime); } self._emit('orientation', sound._id); @@ -403,7 +426,7 @@ * with `inverse` and `exponential`. * panningModel - ('HRTF' by default) Determines which spatialization algorithm is used to position audio. * Can be `HRTF` or `equalpower`. - * + * * @return {Howl/Object} Returns self or current panner attributes. */ Howl.prototype.pannerAttr = function() { @@ -578,8 +601,12 @@ sound._panner.refDistance = sound._pannerAttr.refDistance; sound._panner.rolloffFactor = sound._pannerAttr.rolloffFactor; sound._panner.panningModel = sound._pannerAttr.panningModel; - sound._panner.setPosition(sound._pos[0], sound._pos[1], sound._pos[2]); - sound._panner.setOrientation(sound._orientation[0], sound._orientation[1], sound._orientation[2]); + sound._panner.positionX.setValueAtTime(sound._pos[0], Howler.ctx.currentTime); + sound._panner.positionY.setValueAtTime(sound._pos[1], Howler.ctx.currentTime); + sound._panner.positionZ.setValueAtTime(sound._pos[2], Howler.ctx.currentTime); + sound._panner.orientationX.setValueAtTime(sound._orientation[0], Howler.ctx.currentTime); + sound._panner.orientationY.setValueAtTime(sound._orientation[1], Howler.ctx.currentTime); + sound._panner.orientationZ.setValueAtTime(sound._orientation[2], Howler.ctx.currentTime); } else { sound._panner = Howler.ctx.createStereoPanner(); sound._panner.pan.setValueAtTime(sound._stereo, Howler.ctx.currentTime);