Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing Sound In Hidden Tag

Tags:

html

audio

I am trying to set sound on web page.

I found this code. It is working code when the div is visible but I want to be hidden and working. In this case it is not working because it is hidden with style attribute. How to make it not visible and playing sound at the same time ?

<div style="display:none">
   <embed src="sound.mp3"/> 
</div>
like image 937
theChampion Avatar asked Mar 20 '13 20:03

theChampion


People also ask

How can I make my audio player invisible in HTML?

You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <audio> element is not visible, but it maintains its position on the page.

How do I hide audio player?

Long-press of the folders/files to show hidden options. Tap on the menu icon and select Hide. This will hide the folder and all the files saved within. Now, when you open the music player app, you won't see these audio file formats with your songs.

How do you set an audio tag to play automatically?

The autoplay attribute is a boolean attribute. When present, the audio will automatically start playing as soon as it can do so without stopping. Note: Chromium browsers do not allow autoplay in most cases. However, muted autoplay is always allowed.

How do I embed a sound in HTML?

To embed audio in HTML, we use the <audio> tag.


1 Answers

I agree with the sentiment in the comments above — this can be pretty annoying. We can only hope you give the user the option to turn the music off.

However...

audio { display:none;}
<audio autoplay="true" src="https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg">

The css hides the audio element, and the autoplay="true" plays it automatically.

like image 188
couzzi Avatar answered Nov 14 '22 18:11

couzzi