Skip to content

Fix iOS control center notification in html5 mode #1530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix iOS control center notification #1383
When html5 is forced, we don't really need to setupAudioContext.
When it's called too early, it unnecessarily creates a Web Audio gain
node which breaks the notification on iOS.
  • Loading branch information
bikubi committed Nov 19, 2021
commit dbc0b70d51d8afbb396450cbe6bee17130ec1779
20 changes: 12 additions & 8 deletions src/howler.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,6 @@
init: function(o) {
var self = this;

// If we don't have an AudioContext created yet, run the setup.
if (!Howler.ctx) {
setupAudioContext();
}

// Setup user-defined default properties.
self._autoplay = o.autoplay || false;
self._format = (typeof o.format !== 'string') ? o.format : [o.format];
Expand All @@ -596,6 +591,17 @@
withCredentials: o.xhr && o.xhr.withCredentials ? o.xhr.withCredentials : false,
};

if (!self._html5) {
// If we're not forcing HTML5 and we don't have an AudioContext created yet, run the setup.
if (!Howler.ctx) {
// sets Howler.usingWebAudio
setupAudioContext();
}
} else {
Howler.usingWebAudio = false;
}
self._webAudio = Howler.usingWebAudio;

// Setup all other default properties.
self._duration = 0;
self._state = 'unloaded';
Expand All @@ -620,9 +626,6 @@
self._onunlock = o.onunlock ? [{fn: o.onunlock}] : [];
self._onresume = [];

// Web Audio or HTML5 Audio?
self._webAudio = Howler.usingWebAudio && !self._html5;

// Automatically try to enable audio.
if (typeof Howler.ctx !== 'undefined' && Howler.ctx && Howler.autoUnlock) {
Howler._unlockAudio();
Expand Down Expand Up @@ -2543,6 +2546,7 @@

// Create and expose the master GainNode when using Web Audio (useful for plugins or advanced usage).
if (Howler.usingWebAudio) {
// note: this part breaks iOS 13.3+ ControlCenter notification
Howler.masterGain = (typeof Howler.ctx.createGain === 'undefined') ? Howler.ctx.createGainNode() : Howler.ctx.createGain();
Howler.masterGain.gain.setValueAtTime(Howler._muted ? 0 : Howler._volume, Howler.ctx.currentTime);
Howler.masterGain.connect(Howler.ctx.destination);
Expand Down