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.

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

Related posts

Securing client-side JavaScript

Tightening up my content security policy.

My approach to HTML web components

Naming custom elements, naming attributes, the single responsibility principle, and communicating across components.

Pickin’ dates

HTML web components for augmenting date inputs.

Speedy tunes

Improving performance on The Session.

Relative times

Messing around with Intl.RelativeTimeFormat on The Session.

Related links

abc to SVG | CSS-Tricks

Aw, this is so nice! Chris points to the way that The Session generates sheet music from abc text:

The SVG conversion is made possible entirely in JavaScript by an open source library. That’s the progressive enhancement part. Store and ship the basic format, and let the browser enhance the experience, if it can (it can).

Here’s another way of thinking of it: I was contacted by a blind user of The Session who hadn’t come across abc notation before. Once they realised how it worked, they said it was like having alt text for sheet music! 🤯

Tagged with

WebKit Features in Safari 17.4 | WebKit

It’s a shame that the newest Safari release is overshadowed by Apple’s shenanigans and subsequent U-turn because there’s some great stuff in there.

I really like what they’re doing with web apps added to the dock:

Safari adds support for the shortcuts manifest member on macOS Sonoma. This gives you a mechanism in the manifest file for defining custom menu commands that will appear in the File menu and the Dock context menu.

Tagged with

Web Push on iOS - 1 year anniversary - Webventures

Web Push on iOS is nearing its one year anniversary. It’s still mostly useless.

Sad, but true. And here’s why:

On iOS, for a website to be able to ask the user to grant the push notification permission, it needs to be installed to the home screen.

No other browser on any of the other platforms requires you to install a website for it to be able to send push notifications.

Apple is within their rights to withhold Web Push to installed apps. One could argue it’s not even an unreasonable policy - if Apple made installing a web app at least moderately straightforward. As it is, they have buried it and hidden important functionality behind it.

I really, really hope that the Safari team are reading this.

Tagged with

The Biggest Thing from WWDC 2022 - Webventures

Web Push on iOS will change the “we need to build a native app” decision.

I agree.

Push notifications are definitely not the sole reason to go native, but in my experience, it’s one of the first things clients ask for. They may very well be the thing that pushes your client over the edge and forces them, you and the entire project to accept the logic of the app store model.

Tagged with

Introducing Opportunities & Experiments: Taking the Guesswork out of Performance - WebPageTest Blog

WebPageTest just got even better! Now you can mimic the results of what would’ve previously required actually shipping, like adding third-party scripts, switching from a client-rendered to a server-rendered architecture and other changes that could potentially have a big effect on performance. Now you can run an experiment to get the results before actual implementation.

Tagged with

Previously on this day

2 years ago I wrote 02022-02-22

Losing an eleven year bet.

3 years ago I wrote Ten down, one to go

Counting down to 02022-02-22.

7 years ago I wrote Long betting

Over halfway there.

11 years ago I wrote Jets dream

A modest proposal for long-distance air travel.

13 years ago I wrote The long prep

Care to place a wager?

16 years ago I wrote Thai-ing the knot

Going east.

16 years ago I wrote Resolved

The search on Upcoming has been fixed.

19 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.

20 years ago I wrote Teleport

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

22 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.

22 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".

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

Now America has a faith-based war.