0

I want to play a sound on my website, but it doesn't work. I've already tried everything:

<audio id="ringtone" src="Sound2.mp3"></audio>
RingSound = document.getElementById("ringtone");
RingSound.play();

I also tried another method:

var Sound = new Audio('Sound2.mp3')
Sound.play();

Everything didn't work out, but the sound of the computer works. I've tried almost everything, moved the file, done audio test. I hope someone can help me

Erich Kitzmueller
  • 36,381
  • 5
  • 80
  • 102
  • 2
    The code you've got should work, but note that sound can only be played if the user has 'interacted' with the page - eg. by clicking a button to initiate the sound. You cannot play annoying sounds immediately when the page loads. If you open the console in devtools you'll see a message regarding suppressed sounds if this is the case. – Rory McCrossan Aug 17 '23 at 16:03
  • 1
    Any useful error messages in the browser's console? – Erich Kitzmueller Aug 17 '23 at 16:03
  • 2
    Soft duplicate: [How to make audio autoplay on chrome](https://stackoverflow.com/questions/50490304/how-to-make-audio-autoplay-on-chrome). Other commenters have already addressed that this is largely not possible without the media being triggered as part of a user interaction event. – esqew Aug 17 '23 at 16:04

0 Answers0