How to play Audio Files with JavaScript

  Рет қаралды 54,233

The Wheelchair Guy

The Wheelchair Guy

Күн бұрын

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

Пікірлер: 100
@leonardmbibi8013
@leonardmbibi8013 Жыл бұрын
👍 for the video. I wish you named the variable, "play" differently so it doesn't confuse beginners with the method, "play" within the function.
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
Noted.
@bilegtsdf5776
@bilegtsdf5776 Жыл бұрын
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!!!!🥰
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
Thanks for watching. Enjoy playing audio files
@raven.4815
@raven.4815 Жыл бұрын
Straight to the point, thanks!
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
Thanks for watching
@AyushGupta-xq8fe
@AyushGupta-xq8fe 2 жыл бұрын
Thank You so much Man! I looked for this everywhere and at last it was your video which finally Helped me. Really Thank You!
@TheWheelchairGuy
@TheWheelchairGuy 2 жыл бұрын
Glad I could help! Thanks for watching Ayush
@mateipi
@mateipi 2 жыл бұрын
Thanks! Exactly what I was looking for to upgrade my website!
@TheWheelchairGuy
@TheWheelchairGuy 2 жыл бұрын
Glad I could help!
@bkgraphicdesign3464
@bkgraphicdesign3464 2 ай бұрын
Thank you for the knowledge shared.
@TheWheelchairGuy
@TheWheelchairGuy 2 ай бұрын
Glad it was helpful! Thanks
@arab-blogger
@arab-blogger Жыл бұрын
thanks man keep it up شكرا اخى لقد استمتعت بمشاهدة فيديوهاتك
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
I am happy انا سعيد thank you شكرا
@very-very-bored
@very-very-bored Ай бұрын
You're the best! Thank you so much!
@TheWheelchairGuy
@TheWheelchairGuy Ай бұрын
Glad it helped! Enjoy coding
@waliqadri
@waliqadri Жыл бұрын
Love your videos bro
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
Thanks bro
@PaperaAstrale
@PaperaAstrale 6 ай бұрын
thank you i needed this, also this was clear fast and very easy to understand
@TheWheelchairGuy
@TheWheelchairGuy 6 ай бұрын
Glad it helped! I hope you like and subscribe
@BlocksOfGoldGD
@BlocksOfGoldGD 10 ай бұрын
underrated
@TheWheelchairGuy
@TheWheelchairGuy 10 ай бұрын
Thanks for watching
@michaelshollaj6428
@michaelshollaj6428 Жыл бұрын
Great video, liked and subscribed
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
Big thanks
@oloja__
@oloja__ Жыл бұрын
Nice
@KyleeeYT13
@KyleeeYT13 3 ай бұрын
How do I make an image play an audio when I click it? (pls i need help)
@TheWheelchairGuy
@TheWheelchairGuy 3 ай бұрын
You can basically add onclick=“functionName()” attribute to the image for example
@shahzadnoori8678
@shahzadnoori8678 Жыл бұрын
Thanks for best teach
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
Most welcome
@yevvieart
@yevvieart Жыл бұрын
thank you! i needed an option to include a pronunciation of my name in a portfolio and this is a life saver!
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
Glad to hear that
@jaimefernandopelembe4339
@jaimefernandopelembe4339 7 ай бұрын
Thank you for the video, you helped me very much.
@TheWheelchairGuy
@TheWheelchairGuy 7 ай бұрын
Glad it helped. Thanks for watching
@creo_one
@creo_one 6 ай бұрын
I love it man, thanks!
@TheWheelchairGuy
@TheWheelchairGuy 6 ай бұрын
Glad to hear it! Thank you for watching. I hope you like and subscribe
@ZacDomamuo
@ZacDomamuo Жыл бұрын
absolute legend!!!! Thanks :D
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
Glad it helped!
@bijenderlamba906
@bijenderlamba906 4 ай бұрын
How we do the same if audio is not in the same folder
@kartikeytiwari5388
@kartikeytiwari5388 11 ай бұрын
thanks for the video. imo u should have mentioned that you were using constrcutor while explaining
@TheWheelchairGuy
@TheWheelchairGuy 11 ай бұрын
You are right. I used the constructor implicitly
@user-dr5lh3rc7t
@user-dr5lh3rc7t 2 ай бұрын
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)
@TheWheelchairGuy
@TheWheelchairGuy 2 ай бұрын
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!
@26.muh.zakysyahfadil91
@26.muh.zakysyahfadil91 Жыл бұрын
nice tq
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
Thanks for watching
@vigilanteagle1980
@vigilanteagle1980 Жыл бұрын
thank you, that was very helpful for me
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
Glad to hear that!
@noddygoat
@noddygoat 11 ай бұрын
very cool, thanks! :D
@TheWheelchairGuy
@TheWheelchairGuy 11 ай бұрын
Thanks for watching. Please like and subscribe. The road to 20k
@VolumetrickDST
@VolumetrickDST 3 ай бұрын
THANKYOU
@TheWheelchairGuy
@TheWheelchairGuy 3 ай бұрын
You’reWelcome
@jayparm
@jayparm Жыл бұрын
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
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
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(); }
@israelalcudia9211
@israelalcudia9211 18 күн бұрын
Hello, is it possible to add autoplay with audio in Safari?
@TheWheelchairGuy
@TheWheelchairGuy 18 күн бұрын
Autoplay has been disabled on Chrome and Safari for personal security reasons.
@manishabhatt124
@manishabhatt124 3 ай бұрын
Tq u
@weareloved
@weareloved 10 ай бұрын
Thank you!
@TheWheelchairGuy
@TheWheelchairGuy 10 ай бұрын
You're welcome!
@jefferyaaron3462
@jefferyaaron3462 Жыл бұрын
Thanks bro
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
You’re very welcome bro
@ItachiUchiha-gv5vl
@ItachiUchiha-gv5vl Жыл бұрын
thank you my dude
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
Happy to help
@gabbiimartire9299
@gabbiimartire9299 Жыл бұрын
Gracias. Me salvaste
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
De nada
@mala.m.m
@mala.m.m Жыл бұрын
Hi there. If I would like the audio to simply play on click/tap how do I replace the button line of code?
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
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
@mala.m.m
@mala.m.m Жыл бұрын
@@TheWheelchairGuy Thank you for taking the time to respond! Tis much appreciated
@oneplace-ii1bp
@oneplace-ii1bp 2 ай бұрын
this code not working in iphone browser
@TheWheelchairGuy
@TheWheelchairGuy 2 ай бұрын
Could you please tell me what iPhone are you using?
@kaushalyalakshitha9682
@kaushalyalakshitha9682 Жыл бұрын
Thanx
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
Welcome ✌️
@felix-zp4ie
@felix-zp4ie 9 ай бұрын
thanks!
@TheWheelchairGuy
@TheWheelchairGuy 9 ай бұрын
You bet!
@PeriklesPeriklesoglu
@PeriklesPeriklesoglu Жыл бұрын
thanks
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
You are welcome
@uwotgames
@uwotgames 9 ай бұрын
too confusing i only know html and css and want the text i click to play some audio
@TheWheelchairGuy
@TheWheelchairGuy 9 ай бұрын
Sorry for confusion
@aestellatv6524
@aestellatv6524 Жыл бұрын
doesnt work, i tried with image link and mormal image
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
Make sure you attach the function to an element. For instance, onclick="function()"
@Bignaqc
@Bignaqc Жыл бұрын
The audio isn’t playing
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
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
@rexzy1852
@rexzy1852 Жыл бұрын
how if want auto play?
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
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
@martapfahl940
@martapfahl940 Жыл бұрын
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....
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
This works on computer, but on your mobile, the browser that you run code with might not support JavaScript Audio
@martapfahl940
@martapfahl940 Жыл бұрын
@@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.
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
@@martapfahl940 you can use setInterval to start the function when the timer is done.
@martapfahl940
@martapfahl940 Жыл бұрын
@@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?
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
@@martapfahl940 You can say for instance, whenever variable count down becomes zero, trigger the sound function
@MERV_
@MERV_ Жыл бұрын
I cant get it to work and it's driving me mad
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
You can get the code here. github.com/pescad085/javaScriptAudio/blob/main/Sound.html
@bprodu1
@bprodu1 Жыл бұрын
How to play 4 audio files?
@TheWheelchairGuy
@TheWheelchairGuy Жыл бұрын
I should make a tutorial about that
@aceofspades02
@aceofspades02 5 ай бұрын
works in computer; works not in mobile.
@TheWheelchairGuy
@TheWheelchairGuy 5 ай бұрын
It depends on browsers. Some browsers don’t support JavaScript and autoplay
@masudiqval8575
@masudiqval8575 7 ай бұрын
🦨 🐰🐇 🕊
@TheWheelchairGuy
@TheWheelchairGuy 7 ай бұрын
I don’t know what that means
@JabbaDaHut-v7m
@JabbaDaHut-v7m 5 күн бұрын
Please don't write script code into an html file...
@TheWheelchairGuy
@TheWheelchairGuy 5 күн бұрын
It is optional to write the script in the HTML file or not
Learn HTML audio in 5 minutes! 🔊
5:17
Bro Code
Рет қаралды 74 М.
JavaScript Cookies vs Local Storage vs Session Storage
14:28
Web Dev Simplified
Рет қаралды 746 М.
Just Give me my Money!
00:18
GL Show Russian
Рет қаралды 1000 М.
Now it’s my turn ! 😂🥹 @danilisboom  #tiktok #elsarca
00:20
Elsa Arca
Рет қаралды 12 МЛН
Touching Act of Kindness Brings Hope to the Homeless #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 18 МЛН
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,7 МЛН
Build this JS calculator in 15 minutes! 🖩
15:20
Bro Code
Рет қаралды 526 М.
5 JavaScript Concepts You HAVE TO KNOW
9:38
James Q Quick
Рет қаралды 1,4 МЛН
Audio Play Pause and Stop using JavaScript | Play Audio using JavaScript
8:57
Sounds and Music in JavaScript games (Tutorial)
11:34
Drew Conley
Рет қаралды 18 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 802 М.
Subtle, yet Beautiful Scroll Animations
5:04
Beyond Fireship
Рет қаралды 1,7 МЛН
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 474 М.
How to put an HTML website online (on the Internet)
29:37
SuperSimpleDev
Рет қаралды 1,6 МЛН
Just Give me my Money!
00:18
GL Show Russian
Рет қаралды 1000 М.