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

Комментарии • 98

  • @leonardmbibi8013
    @leonardmbibi8013 Год назад +11

    👍 for the video. I wish you named the variable, "play" differently so it doesn't confuse beginners with the method, "play" within the function.

  • @raven.4815
    @raven.4815 Год назад +4

    Straight to the point, thanks!

  • @bilegtsdf5776
    @bilegtsdf5776 Год назад +2

    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!!!!🥰

  • @AyushGupta-xq8fe
    @AyushGupta-xq8fe 2 года назад +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!

  • @mateipi
    @mateipi 2 года назад +3

    Thanks! Exactly what I was looking for to upgrade my website!

  • @bkgraphicdesign3464
    @bkgraphicdesign3464 2 месяца назад

    Thank you for the knowledge shared.

  • @very-very-bored
    @very-very-bored Месяц назад

    You're the best! Thank you so much!

  • @arab-blogger
    @arab-blogger Год назад

    thanks man keep it up
    شكرا اخى لقد استمتعت بمشاهدة فيديوهاتك

  • @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

  • @waliqadri
    @waliqadri Год назад +1

    Love your videos bro

  • @manishabhatt124
    @manishabhatt124 2 месяца назад

    Tq u

  • @creo_one
    @creo_one 6 месяцев назад

    I love it man, thanks!

    • @TheWheelchairGuy
      @TheWheelchairGuy  6 месяцев назад +1

      Glad to hear it! Thank you for watching. I hope you like and subscribe

  • @michaelshollaj6428
    @michaelshollaj6428 Год назад

    Great video, liked and subscribed

  • @BlocksOfGoldGD
    @BlocksOfGoldGD 9 месяцев назад +1

    underrated

  • @shahzadnoori8678
    @shahzadnoori8678 Год назад

    Thanks for best teach

  • @ZacDomamuo
    @ZacDomamuo Год назад

    absolute legend!!!! Thanks :D

  • @oloja__
    @oloja__ Год назад

    Nice

  • @jaimefernandopelembe4339
    @jaimefernandopelembe4339 7 месяцев назад

    Thank you for the video, you helped me very much.

  • @bijenderlamba906
    @bijenderlamba906 3 месяца назад

    How we do the same if audio is not in the same folder

  • @VolumetrickDST
    @VolumetrickDST 2 месяца назад

    THANKYOU

  • @yevvieart
    @yevvieart Год назад +1

    thank you! i needed an option to include a pronunciation of my name in a portfolio and this is a life saver!

  • @noddygoat
    @noddygoat 10 месяцев назад

    very cool, thanks! :D

    • @TheWheelchairGuy
      @TheWheelchairGuy  10 месяцев назад

      Thanks for watching. Please like and subscribe. The road to 20k

  • @vigilanteagle1980
    @vigilanteagle1980 Год назад

    thank you, that was very helpful for me

  • @KyleeeYT13
    @KyleeeYT13 3 месяца назад +1

    How do I make an image play an audio when I click it? (pls i need help)

    • @TheWheelchairGuy
      @TheWheelchairGuy  3 месяца назад +1

      You can basically add onclick=“functionName()” attribute to the image for example

  • @26.muh.zakysyahfadil91
    @26.muh.zakysyahfadil91 Год назад

    nice tq

  • @kartikeytiwari5388
    @kartikeytiwari5388 10 месяцев назад

    thanks for the video. imo u should have mentioned that you were using constrcutor while explaining

    • @TheWheelchairGuy
      @TheWheelchairGuy  10 месяцев назад

      You are right. I used the constructor implicitly

  • @weareloved
    @weareloved 9 месяцев назад

    Thank you!

  • @gabbiimartire9299
    @gabbiimartire9299 Год назад

    Gracias. Me salvaste

  • @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!

  • @jefferyaaron3462
    @jefferyaaron3462 Год назад

    Thanks bro

  • @kaushalyalakshitha9682
    @kaushalyalakshitha9682 Год назад

    Thanx

  • @ItachiUchiha-gv5vl
    @ItachiUchiha-gv5vl Год назад

    thank you my dude

  • @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  Год назад +2

      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 7 дней назад

    Hello, is it possible to add autoplay with audio in Safari?

    • @TheWheelchairGuy
      @TheWheelchairGuy  6 дней назад

      Autoplay has been disabled on Chrome and Safari for personal security reasons.

  • @PeriklesPeriklesoglu
    @PeriklesPeriklesoglu Год назад

    thanks

  • @felix-zp4ie
    @felix-zp4ie 8 месяцев назад

    thanks!

  • @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?

  • @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

  • @uwotgames
    @uwotgames 9 месяцев назад

    too confusing i only know html and css and want the text i click to play some audio

  • @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

  • @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

  • @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

  • @bprodu1
    @bprodu1 Год назад

    How to play 4 audio files?

  • @aceofspades02
    @aceofspades02 4 месяца назад

    works in computer; works not in mobile.

    • @TheWheelchairGuy
      @TheWheelchairGuy  4 месяца назад

      It depends on browsers. Some browsers don’t support JavaScript and autoplay

  • @masudiqval8575
    @masudiqval8575 7 месяцев назад

    🦨 🐰🐇 🕊