This question already has answers here:
Difference Between HTML <audio>, <bgsound> and <embed> audio tags
(2 answers)
Closed 26 days ago.
I want to play some background music in my own website , I've been searching for 15 minutes and everything seems outdated.
Can someone help me?
<body>
<bgsound src="music/binks.mp3"/>
</body>
<bgsound src="music/binks.mp3"/> ->>> THIS seems to me outdated , and its not working
Should be able to use something like <audio>:
<audio id="background-music" src="path/to/music.mp3" loop></audio>
And then the following in a js file or in a script tag to play the music.
const music = document.getElementById("background-music");
music.play();
Do keep in mind most browser have autoplay policy now, so often the sound will be blocked.
Related
This question already has answers here:
What is the best way to embed Youtube videos? [closed]
(2 answers)
Closed 2 years ago.
I am still pretty new to web developing and i am trying to create a new website for fun and just to test my skills so forget me if i m asking alot from this platform.
but i wanna add a youtube video to my webpage and i can't find anything on stack overflow regarding this but can anyone show me a platform where i can copy/paste the code or someone provide me with it again sorry if asking a lot i have tried github,stack overflow and tried finding on google but everything is related to something else :( any help would be apreciated thank you in advance
You can embed the video on your page using <iframe>. You can find instructions here.
The embed code can easily be found by clicking share button on any YouTube video.
If you're using HTML5, the best way to achieve this is by using the <iframe> tag.
Here is an example (you'll find some stupid dolls jumping and moving):
<iframe src="https://www.youtube.com/embed/tgbNymZ7vqY"></iframe>
autoplay=1 will make the video playing when the page is loaded:
<iframe src="https://www.youtube.com/embed/tgbNymZ7vqY?autoplay=1"></iframe>
But there are two deprecated tags in HTML, I don't recommend to use them.
They are <object> and <embed>.
An example of using <object>:
<object data="https://www.youtube.com/embed/tgbNymZ7vqY"></object>
Another example if using <embed>:
<embed src="https://www.youtube.com/embed/tgbNymZ7vqY">
This question already has answers here:
switch audio source with jquery and HTML5 audio tag
(2 answers)
Closed 3 years ago.
My web page includes a bunch of links that are generated via php. These are links to mp3 files, and right now when I click on them the sound starts playing in a new tab. How can I add a script so that all links start playing the source sound directly in the same tab when clicked (and stop when re-clicked)? Apologies in advance for a possibly stupid question, but please have mercy as I am very new to all of these things.
value1
value2
value3
You should be using an audio tag like the following:
<audio controls>
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
Read more here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/
Also, the target="_blank" attribute will cause the link to open in a new tab.
Good luck on your coding journey!
This question already has an answer here:
Modify default HTML5 video controls
(1 answer)
Closed 6 years ago.
I noticed that in new version of Chrome browser (55.x) the audio player (HTML<audio>) has download button. I see this button in Chrome only and I can't find anything about how to turn it off.
Code:
<audio src="audioUrl.mp3" controls=""></audio>
Ideally I'd like to hide this button but if hiding button is not possible I'd like to prevent downloading file when button pressed. I couldn't find any ondownload event where I could do such thing.
Any help will be appreciated.
"In reality, you can't. But you can make it harder to download."
The full response is here: Prevent HTML5 video from being downloaded (right-click saved)?
This question already has an answer here:
"Autoplay" HTML5 audio player on mobile browsers
(1 answer)
Closed 6 years ago.
I have created a webpage using html and css, I wanted to start an audio file in the background automatically once the page is loaded. Thus I have used <audio> tag in my code.
Now, this works perfectly fine when I open my page in my desktop, but when I open same page through mobile's browser, audio does not starts automatically. It requires manual option.
Can anyone provide me with the solution?
Most of the mobile browsers don't support audio autoplay to save mobile bandwidth on behalf of the user! The similar issue already discussed before, but i have something to share with you which may help you out.
Chrome does not allow applications to play HTML5 audio
after googlling little bit i found an article on codeproject which is really helpful in your case. here is the link.
Fix autoplay issue in mobile browser
i hope it will help you to come out from trouble, thanks.
This question already has answers here:
How to play audio?
(22 answers)
Closed 9 years ago.
I want to make an online metronome using JavaScript. Recently people around me started needing them but there isn't any decent one that doesn't use Flash. So I thought why not.
Before starting I want to make sure it's possible to do this with JavaScript. Basically all I need to know is if it's possible to output a sound, if it is then the rest should be simple enough.
So is it possible? If yes, how?
P.S.: I checked the HTML5 audio tag and I don't think it's gonna work. It's not one long file with the metronome sounds. It's a loop that runs the sound every time it should.
The audio tag is the right tool for this:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio
Create an audio tag - something like:
<audio id="m" loop>
<source src="metronome.mp3">
</audio>
And either make it loop using the appropriate options on the tag (loop), or you can script it in JS:
<script>
// goes inside whatever event handler - when the user clicks a button, timer, etc.
document.getElementById('m').play(); // play the sound
</script>
This article provides a good introduction:
http://html5doctor.com/native-audio-in-the-browser/
If you need it to work in older browsers, you can resort to using Flash (which is "traditionally" how this sort of thing has been done). But as you mention - it's a good idea to avoid this for new development. The audio tag is supported in IE9+ and Chrome, FF, Safari, Opera.
You can use my play() function: http://pastebin.com/GKRx0GDk
It uses the HTML5 audio tag.
play('click.wav');
Just put that on a setInterval if you need it to repeat at a certain time.