1

I was writing an html code with the following code:

<audio src="/home/user/public_html/copyrighted-music.mp3" hidden autoplay><embed src="/home/user/public_html/copyrighted-music.mp3" width="180" height="90" hidden="true"></audio>

I used an <embed> for those people without <audio> supported browsers but with or without the embed tag, the audio only plays when the submit button of my random form is pressed although I was expecting audio to play after it has loaded and not after a press of a button. Just some more background information:

  1. the /home/user/public_html/ is the path of my file I am using with my web host
  2. my web host is x10 hosting
  3. I tried different arrangements of audio and embed arguments and the same result is present
  4. I also have a back to top button which somehow stops the audio from playing after the submit button is pressed
  5. I notice the link changes once each of the two buttons is pressed so maybe the audio likes a certain link?
  6. I have a javascript controlled welcoming pop-up that also comes in action once loaded

So again, how do I make audio play once loaded and not after a press of a submit button?

Kaiido
  • 123,334
  • 13
  • 219
  • 285
  • https://developers.google.com/web/updates/2017/09/autoplay-policy-changes – Kaiido Mar 27 '19 at 02:59
  • Chrome makes autoplay audio near impossible [read this](https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide) and despair – zer00ne Mar 27 '19 at 03:00
  • Possible duplicate of [How to make audio autoplay on chrome](https://stackoverflow.com/questions/50490304/how-to-make-audio-autoplay-on-chrome) But beware two most upvoted answers are relying on bugs (which seem to have been fixed already) – Kaiido Mar 27 '19 at 03:09
  • The problem still is there on my friend's mobile safari, and I am using a web host not the default chrome html runner. Also, the audio actually plays on my chrome, just not automatically, it is with the help of a submit button. –  Mar 27 '19 at 14:56
  • it isn't duplicate but it help fix my problem with my web host running in chrome, I am not sure about my friend's safari problem though... –  Mar 28 '19 at 02:53

3 Answers3

0

I think that you need to learn some JavaScript to improve your code. The HTML5 has a tag named input ,you need to use it and write some ECMAScript to use together. This is my web code about the music,I think this can be a example to you.

<input type="bottom" value="music" onclick="music()">
<script>

function music() {
    var change_music = document.body.createElement("audio");
    change_music.autoplay = 1;
    change_music.controls = 1;
    change_music.src = "/home/user/public_html/copyrighted-music.mp3";
    document.body.append(music);
    };
</script>
gameon67
  • 3,981
  • 5
  • 35
  • 61
God.wang
  • 1
  • 1
  • umm... all it gives is a text input and the `onclick` function doesn't work –  Mar 28 '19 at 02:41
0

try this:

<audio controls autoplay>
<src="/home/user/public_html/copyrighted-music.mp3" hidden autoplay>
<embed src="/home/user/public_html/copyrighted-music.mp3" width="180" height="90" hidden="true">
</audio>
PHP Geek
  • 3,949
  • 1
  • 16
  • 32
  • I prefer no controls and is there such thing as a `` tag? also, I know how remove control argument to remove controls –  Mar 27 '19 at 15:34
-1
<audio controls>
 <source src="/home/user/public_html/copyrighted-music.mp3" type="audio/mpeg">
</audio>

Yous should probaly read more on audio in html5 espcially from w3schools site. By the way why on earth are using copyrighted-music.mp3?

  • it was a name replacement I am using for this question in case someone thinks I took credit –  Mar 27 '19 at 14:46