Monday, 11 October 2021

Using AudioContext stops the audio from playing in the background

I've been playing around with the Web Audio API and ran into a weird problem.

At the moment, if you open a web page on your phone and click the play button on an HTML5 audio element, the audio will keep playing in the background even after switching apps.

However, when you attach the element to an AudioContext, the audio will stop playing in the background after switching apps.

To attach the element, I'm using the following:

const context = new AudioContext()
const source = context.createMediaElementSource(document.querySelector("audio"))

source.connect(context.destination)

So even though I'm simply connecting the HTML5 audio element to the context's destination WITHOUT controlling it, the audio stops playing as soon as I switch apps.

Does anyone know why this is happening and how I can get the audio to keep playing in the background even after switching apps? It's odd that we can use the Web Audio API to control audio on the web, but we have to keep our browsers open and our phones unlocked to listen to that audio.



from Using AudioContext stops the audio from playing in the background

No comments:

Post a Comment