Skip to content

Commit

Permalink
Fix iphone silent switch webaudio mute (#2686)
Browse files Browse the repository at this point in the history
fix iphone silent switch mode when using webaudio so it continues playing audio

* Update CHANGES.md
  • Loading branch information
entonbiba committed Mar 1, 2023
1 parent 4a84fc3 commit 320f114
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ wavesurfer.js changelog
------------------
- Regions plugin:
- Improved delta calculation (resize end) (#2641)
- Fix iphone silent switch webaudio mute (#2667)

6.4.0 (05.11.2022)
------------------
Expand Down
7 changes: 7 additions & 0 deletions src/util/silence-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
* @since 5.2.0
*/
export default function ignoreSilenceMode() {
// Set webaudio context with 1 second silent audio 44100 bit rate buffer to allow playing audio even if silent switch is on the device
const silentAC = new AudioContext();
const silentBS = silentAC.createBufferSource();
silentBS.buffer = silentAC.createBuffer(1, 1, 44100);
silentBS.connect(silentAC.destination);
silentBS.start();

// Set the src to a short bit of url encoded as a silent mp3
// NOTE The silence MP3 must be high quality, when web audio sounds are played
// in parallel the web audio sound is mixed to match the bitrate of the html sound
Expand Down

0 comments on commit 320f114

Please sign in to comment.