I have an audio
HTML element with background music for a game:
<audio class="music" src="..." loop></audio>
Then I have a JS event listener that starts playing it with .play()
on user interaction. The problem is, I noticed that on loading the page, I can control the music from the OS/browser’s media controls.
I can control it from Chrome:
And my macOS media controls also show up:
How can I "hide" this from the browser so that it doesn’t show up like this?
3
Answers
You can use
AudioContext
and load an audio track usingdecodeAudioData()
to play it.Here is a sample implementation: