Web Audio API update on iOS

I documented a weird bug with web audio on iOS a while back:

On some pages of The Session, as well as the audio player for tunes (using the Web Audio API) there are also embedded YouTube videos (using the video element). Press play on the audio player; no sound. Press play on the YouTube video; you get sound. Now go back to the audio player and suddenly you do get sound!

It’s almost like playing a video or audio element “kicks” the browser into realising it should be playing the sound from the Web Audio API too.

This was happening on iOS devices set to mute, but I was also getting reports of it happening on devices with the sound on. But it’s that annoyingly intermittent kind of bug that’s really hard to reproduce consistently. Sometimes the sound doesn’t play. Sometimes it does.

I found a workaround but it was really hacky. By playing a one-second long silent mp3 file using audio, you could “kick” the sound into behaving. Then you can use the Web Audio API and it would play consistently.

Well, that’s all changed with the latest release of Mobile Safari. Now what happens is that the Web Audio stuff plays …for one second. And then stops.

I removed the hacky workaround and the Web Audio API started behaving itself again …but your device can’t be set to silent.

The good news is that the Web Audio behaviour seems to be consistent now. It only plays if the device isn’t muted. This restriction doesn’t apply to video and audio elements; they will still play even if your device is set to silent.

This descrepancy between the two different ways of playing audio is kind of odd, but at least now the Web Audio behaviour is predictable.

You can hear the Web Audio API in action by going to any tune on The Session and pressing the “play audio” button.

Have you published a response to this? :

Responses

Simon Elvery

@adactio weird restrictions for sure. just tried it out and toggling the mute switch on my iPhone 13 with iOS 16.2 mid playback does work for me. 🤷‍♂️

# Posted by Simon Elvery on Wednesday, February 22nd, 2023 at 11:02am

2 Shares

# Shared by Kat M. Moss on Wednesday, February 22nd, 2023 at 1:52pm

# Shared by busticated on Wednesday, February 22nd, 2023 at 2:53pm

2 Likes

# Liked by Kat M. Moss on Wednesday, February 22nd, 2023 at 1:52pm

# Liked by busticated on Wednesday, February 22nd, 2023 at 2:53pm

Previously on this day

1 year ago I wrote 02022-02-22

Losing an eleven year bet.

2 years ago I wrote Ten down, one to go

Counting down to 02022-02-22.

6 years ago I wrote Long betting

Over halfway there.

10 years ago I wrote Jets dream

A modest proposal for long-distance air travel.

12 years ago I wrote The long prep

Care to place a wager?

15 years ago I wrote Thai-ing the knot

Going east.

15 years ago I wrote Resolved

The search on Upcoming has been fixed.

18 years ago I wrote Another day, another micropayment

Jason Kottke has given up his day job. He is now attempting to make a living from personal publishing.

19 years ago I wrote Teleport

I took a trip on Friday to see the good folks over at Motionpath.

21 years ago I wrote Quest for an iMac

Seems like I’m not the only one who has had trouble trying to get hold of an iMac for a test-drive.

21 years ago I wrote Bring on the dancing iMacs

According to this list, one of the things to be avoided in any blog is "your Mac fetish".

21 years ago I wrote Ashcroft Invokes Religion In U.S. War on Terrorism

Now America has a faith-based war.