|
235 | 235 | // By calling Howler.unload(), we create a new AudioContext with the correct sampleRate.
|
236 | 236 | Howler.unload();
|
237 | 237 |
|
| 238 | + // Scratch buffer for enabling iOS to dispose of web audio buffers correctly, as per: |
| 239 | + // http://stackoverflow.com/questions/24119684 |
| 240 | + self._scratchBuffer = ctx.createBuffer(1, 1, 22050); |
| 241 | + |
238 | 242 | // Call this method on touch start to create and play a buffer,
|
239 | 243 | // then check if the audio actually played to determine if
|
240 | 244 | // audio has now been unlocked on iOS, Android, etc.
|
|
413 | 417 | self._webAudio = usingWebAudio && !self._html5;
|
414 | 418 |
|
415 | 419 | // Automatically try to enable audio on iOS.
|
416 |
| - if (typeof ctx !== 'undefined' && ctx) { |
417 |
| - // Scratch buffer for enabling iOS to dispose of web audio buffers correctly, as per: |
418 |
| - // http://stackoverflow.com/questions/24119684 |
419 |
| - self._scratchBuffer = ctx.createBuffer(1, 1, 22050); |
420 |
| - |
421 |
| - if (Howler.mobileAutoEnable) { |
422 |
| - Howler._enableMobileAudio(); |
423 |
| - } |
| 420 | + if (typeof ctx !== 'undefined' && ctx && Howler.mobileAutoEnable) { |
| 421 | + Howler._enableMobileAudio(); |
424 | 422 | }
|
425 | 423 |
|
426 | 424 | // Keep track of this Howl group in the global controller.
|
|
1697 | 1695 | _cleanBuffer: function(node) {
|
1698 | 1696 | var self = this;
|
1699 | 1697 |
|
1700 |
| - node.bufferSource.onended = null; |
1701 |
| - node.bufferSource.disconnect(0); |
1702 |
| - try { node.bufferSource.buffer = self._scratchBuffer; } catch(e) {} |
| 1698 | + if (self._scratchBuffer) { |
| 1699 | + node.bufferSource.onended = null; |
| 1700 | + node.bufferSource.disconnect(0); |
| 1701 | + try { node.bufferSource.buffer = self._scratchBuffer; } catch(e) {} |
| 1702 | + } |
1703 | 1703 | node.bufferSource = null;
|
1704 | 1704 |
|
1705 | 1705 | return self;
|
|
0 commit comments