Skip to content

Commit 982c0aa

Browse files
committed
Setup scratch buffer after mobile unload
1 parent 2e53ac2 commit 982c0aa

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/howler.core.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@
235235
// By calling Howler.unload(), we create a new AudioContext with the correct sampleRate.
236236
Howler.unload();
237237

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+
238242
// Call this method on touch start to create and play a buffer,
239243
// then check if the audio actually played to determine if
240244
// audio has now been unlocked on iOS, Android, etc.
@@ -413,14 +417,8 @@
413417
self._webAudio = usingWebAudio && !self._html5;
414418

415419
// 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();
424422
}
425423

426424
// Keep track of this Howl group in the global controller.
@@ -1697,9 +1695,11 @@
16971695
_cleanBuffer: function(node) {
16981696
var self = this;
16991697

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+
}
17031703
node.bufferSource = null;
17041704

17051705
return self;

0 commit comments

Comments
 (0)