0

Beginner coder here, having an HTML issue. I've been trying to make a website with looping music, but I've been having trouble making the music "loop".

`
<embed 
src="music/dokitrash.mp3";
loop='true';
autostart='true';
hidden='true';
volume='70';></embed>`

Does anybody know where I went wrong? I put this block of code in between the end of head and above body.

  • Dear @gabeywabey : I have highlighted issues with your audio embedding in my answer. If you need more help, just drop me a message. Do rate my answer and accept it by clicking on the tick icon on the left side of my answer, if you learned new stuff today from me and if your problem is resolved. Happy coding – Imran Rafiq Rather Dec 16 '20 at 13:18

2 Answers2

0

You could try 2 ways.

First:

<embed 
src="music/dokitrash.mp3"
loop="true"
autostart="true"
hidden="true"
volume="70"></embed>`

or second:

<embed 
src="music/dokitrash.mp3"
loop=2 //here you can put any number to represent the number of times you want to loop
autostart="true"
hidden="true"
volume="70"></embed>`

Don't use ";" in html tags

EDIT:

Well, you have another way to do this.

<audio>
    <source src="sample.mp3" type="audio/mpeg">
</audio>

Like your embed is with an mp3 file, this is the best way to accomplish what you want.

southernegro
  • 384
  • 4
  • 20
  • Neither of these worked prior, and neither work currently sadly. Could it be something else maybe? – gabeywabey Dec 15 '20 at 21:11
  • JUst edit my answer, try that. If it works you could accept my answer. thanks. source: https://www.geeksforgeeks.org/how-to-embed-audio-element-in-a-html-document/ – southernegro Dec 16 '20 at 12:20
0

Let me highlight some of the mistakes you have made and the right approach to do this.

  1. embed tag in HTML5 has 4 main attributes which are height, src, type and width, besides few other that can be used. (Visit https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed).And in your code apart from src attribute none is executed. And hence loop="true" also doesn't execute. Besides this "There are also syntax errors in your code.You cannot use terminator (;) after providing a property value in a tag here"
  2. loop, autoplay etc are attributes of the <audio> tag (visit https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio)
  3. The HTML <embed> element embeds external content at the specified point in the document. This content is provided by an external application or other source of interactive content such as a browser plug-in. So, we can embed other HTML elements in <embed> element like <object>, <video> etc but the Browser support is not that good.
  4. Recommended approach: To use embed audio in your case would be to use the HTML5 <audio> element. This will give you access to lots of properties that will be helpful to customize your audio.

 <audio controls loop autoplay id="myAudio">
  <source src= "https://s3.amazonaws.com/freecodecamp/drums/Heater-1.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

Please Note: On Chrome autoplay doesn't work and needs a work-around. Get that from How to make audio autoplay on chrome

Imran Rafiq Rather
  • 7,677
  • 1
  • 16
  • 35
  • Actually, autoplay is working for me, for some reason. The loop works now, but there's still an underlying issue. The audio only plays for me, and nobody else who I've given the link to, it's only played for them when I used the tag. – gabeywabey Dec 16 '20 at 13:36
  • The audio also played on my Opera Browser and Edge Browser but not on Chrome Browser. For that I told the reason :) Now coming to your second part of the question. The audio file that you have is in your own computer. So obviously it will not work for others. Could you put your code, that worked for you on jsfiddle and share the link with me. I would like to see why is it playing for you now. Could come up with the reason about why it will be working, :) – Imran Rafiq Rather Dec 16 '20 at 13:59