How to play Audio Files with JavaScript
HTML-код
- Опубликовано: 25 авг 2024
- I will show you how to play audio files using Java Script on Visual Studio Code. Code training for beginners. JavaScript for everyone
source code github.com/pes...
#javascript #tutorial #trending
👍 for the video. I wish you named the variable, "play" differently so it doesn't confuse beginners with the method, "play" within the function.
Noted.
Straight to the point, thanks!
Thanks for watching
You've been my angel ever since I couldn't upload images in HTML, I love you, my man, you're one of the gods on youtube. keeeeeep goooiiing!!!!🥰
Thanks for watching. Enjoy playing audio files
Thank You so much Man! I looked for this everywhere and at last it was your video which finally Helped me. Really Thank You!
Glad I could help! Thanks for watching Ayush
Thanks! Exactly what I was looking for to upgrade my website!
Thank you for the knowledge shared.
Glad it was helpful! Thanks
You're the best! Thank you so much!
Glad it helped! Enjoy coding
thanks man keep it up
شكرا اخى لقد استمتعت بمشاهدة فيديوهاتك
I am happy انا سعيد
thank you شكرا
thank you i needed this, also this was clear fast and very easy to understand
Glad it helped! I hope you like and subscribe
Love your videos bro
Thanks bro
Tq u
I love it man, thanks!
Glad to hear it! Thank you for watching. I hope you like and subscribe
Great video, liked and subscribed
Big thanks
underrated
Thanks for watching
Thanks for best teach
Most welcome
absolute legend!!!! Thanks :D
Glad it helped!
Nice
Thank you for the video, you helped me very much.
Glad it helped. Thanks for watching
How we do the same if audio is not in the same folder
THANKYOU
You’reWelcome
thank you! i needed an option to include a pronunciation of my name in a portfolio and this is a life saver!
Glad to hear that
very cool, thanks! :D
Thanks for watching. Please like and subscribe. The road to 20k
thank you, that was very helpful for me
Glad to hear that!
How do I make an image play an audio when I click it? (pls i need help)
You can basically add onclick=“functionName()” attribute to the image for example
nice tq
Thanks for watching
thanks for the video. imo u should have mentioned that you were using constrcutor while explaining
You are right. I used the constructor implicitly
Thank you!
You're welcome!
Gracias. Me salvaste
De nada
Thank you! But How if the server doesn’t allow to upload .mp3?? Is there any alter solutions for making music player at browser? (sorry for my terrible english)
Hi there. I'm not sure if this will work, but you could try uploading the audio file to GitHub and copying the source code. This is just a suggestion, though.
Also, I just wanted to say that your English is very good!
Thanks bro
You’re very welcome bro
Thanx
Welcome ✌️
thank you my dude
Happy to help
How do you let it select an audio file randomly to play from a folder?
AND
How do you make a transition sort of thing (play a file during songs)
AKA a radio
You can try something like this:
const musicFiles = ["music1.mp3", "music2.mp3", "music3.mp3"];
const audio = new Audio();
function playRandomMusic() {
const randomIndex = Math.floor(Math.random() * musicFiles.length);
audio.src = musicFiles[randomIndex];
audio.play();
}
Hello, is it possible to add autoplay with audio in Safari?
Autoplay has been disabled on Chrome and Safari for personal security reasons.
thanks
You are welcome
thanks!
You bet!
this code not working in iphone browser
Could you please tell me what iPhone are you using?
Hi there. If I would like the audio to simply play on click/tap how do I replace the button line of code?
You basically add the onclick=“functionName()” to any html element. See all touch events here developer.mozilla.org/en-US/docs/Web/API/Touch_events
@@TheWheelchairGuy Thank you for taking the time to respond! Tis much appreciated
too confusing i only know html and css and want the text i click to play some audio
Sorry for confusion
doesnt work, i tried with image link and mormal image
Make sure you attach the function to an element. For instance, onclick="function()"
The audio isn’t playing
Check your code and make sure to place the script before the end of the body tag. You can get my code in the description of this video
I cant get it to work and it's driving me mad
You can get the code here. github.com/pescad085/javaScriptAudio/blob/main/Sound.html
how if want auto play?
You can try something like
window.onload = function() {
var audio = new Audio('audio_file.mp3');
audio.play();
}
However, some browsers do not allow this because of safety concerns
Do you know how to make it work on mobile? I have a Timer that counts down and when expired on desktop it will fire the audio but not on mobile....
This works on computer, but on your mobile, the browser that you run code with might not support JavaScript Audio
@@TheWheelchairGuy Is there a way to make it possible? I have built a pomodoro timer app with React so having no audio when timer is expired would really suck.
@@martapfahl940 you can use setInterval to start the function when the timer is done.
@@TheWheelchairGuy You mean start the interval when the user clicked the timer? The problem is the user can pause the timer so the sound would fire earlier then... But you confirm there is no other option that user events to trigger sounds on mobile?
@@martapfahl940 You can say for instance, whenever variable count down becomes zero, trigger the sound function
How to play 4 audio files?
I should make a tutorial about that
works in computer; works not in mobile.
It depends on browsers. Some browsers don’t support JavaScript and autoplay
🦨 🐰🐇 🕊
I don’t know what that means