-1

I'm trying to make web page in which there will be music playing in background.

<!DOCTYPE html>
<html lang="pl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> Website </title>
    
</head>
<body>
    <h2>Welcome to my website</h2>
    <audio src="sound.mp3" controls autoplay>
        <p>If you are reading this, it is because your browser does not support the audio element.     </p>
    </audio>
</body>
</html>


You can see audio player, so web page can find mp3 file for sure.(https://i.stack.imgur.com/4GERM.png)

I tried many different approaches (audio tag, embed tag, iframe, some js scripts) but I can only make audio player and I have to turn on music manually, and I can't find way to start playing music, when i enter web page. My browser is opera gx, but i tried also do this in edge with same results. Do you have any ideas how to make it work?

  • Playing music or video automatically without user input is considered abhorrent and intrusive. From Google: "From the user's perspective, a web page or app that spontaneously starts making noise without warning can be jarring, inconvenient, or off-putting. Because of that, browsers generally only allow autoplay to occur successfully under specific circumstances." – Stu Feb 26 '23 at 11:48

2 Answers2

0

Many browsers block web pages from auto-playing audio

This is because many people (including me!) are annoyed when web pages play sounds without their permission, since they may be in a quiet area, where it is disruptive to others.

Chrome is a good example

Google explained this in this blog post: https://developer.chrome.com/blog/autoplay/

More information on the Chromium project website: https://sites.google.com/a/chromium.org/dev/audio-video/autoplay

Try different browsers

You might find a browser that is less thoughtful. This might be acceptable to you, if it is just for your own use, or your end-users are happy to have auto-playing sound and therefore to use a particular browser for your page.

ProfDFrancis
  • 8,816
  • 1
  • 17
  • 26
0

This is because Chromium-based browsers disallow autoplay

There are plenty of possible approaches discussed here, or you can simply Google for "autoplay audio in chromium browsers" to find more.

Ellrohir
  • 1,017
  • 1
  • 14
  • 32