Playing Sounds in Your React App | Tutorial

Поділитися
Вставка
  • Опубліковано 6 лют 2025

КОМЕНТАРІ • 62

  • @kandekore
    @kandekore 2 роки тому +11

    after many Stackoverflow and youtube search, this video provided a simple solution. Thank you

    • @NiklasZiermann
      @NiklasZiermann  2 роки тому +1

      You're welcome. I'm glad I could help :)

  • @lucasmarques2871
    @lucasmarques2871 Рік тому +5

    Straight to the point, thank you very much!

  • @sebastianlozano7707
    @sebastianlozano7707 11 місяців тому

    straigth to the point! Thanks so much

  • @linak1909
    @linak1909 11 місяців тому

    Thank you so much for this excellent tutorial🙏 straight to the point

    • @NiklasZiermann
      @NiklasZiermann  11 місяців тому

      You're welcome. I'm glad I could help :)

  • @c_zeroyt2556
    @c_zeroyt2556 Рік тому

    Thank you , best one on youtube

  • @seraphitssingh973
    @seraphitssingh973 2 роки тому +1

    This is what I need. Thank you.

  • @andrew52600
    @andrew52600 Рік тому

    Excellent video.

  • @brandonmchugh9821
    @brandonmchugh9821 2 роки тому

    Amazing. This is exactly what I was looking for. THanks!!!!!

  • @max_heeden
    @max_heeden 7 місяців тому

    Good video. Thanks!

  • @chrisgraham2123
    @chrisgraham2123 2 роки тому

    perfect man subbed, thanks a ton!

    • @NiklasZiermann
      @NiklasZiermann  2 роки тому +1

      You're welcome. I'm glad you enjoyed the video :)

  • @lucasmanoel208
    @lucasmanoel208 Рік тому

    Thank you, meu chapa!

  • @Tube-hn9rc
    @Tube-hn9rc Рік тому

    thank you sir that is really helpfull

  • @reise254
    @reise254 Рік тому +3

    (edit, added howler)
    This worked thanks! But..
    after a while I got a "distorted/corrupted" sound. Tried everything, the only fix that worked for me was using Howler library instead of the built in HTML audio player in the video.
    $ `npm i howler`

    • @NiklasZiermann
      @NiklasZiermann  Рік тому +1

      That's unfortunate. Sorry to hear that... But thank you for pointing out an alternative solution :)

    • @amanrubey
      @amanrubey Рік тому

      thanks!!!!! howler indeed worked, nothing else was working and I was exasperated and so depressed

  • @web.mayk3l
    @web.mayk3l 10 місяців тому

    Nice video

  • @harshitsuyal8285
    @harshitsuyal8285 2 роки тому

    Thankyou so much brother it’s very helpfull

  • @luv.matters
    @luv.matters Рік тому +1

    Now how do you do it with multiple sounds like a drumkit?

    • @NiklasZiermann
      @NiklasZiermann  Рік тому

      Just create one Audio object for each sound and play them accordingly :)

  • @payamrezaei-eg8dz
    @payamrezaei-eg8dz 9 місяців тому

    i have impelementing an book with audio sound for each paragraph that api gives me the audio files by each api call and i want make toggle button to play and pause and other buttons not work till get pause or ended

    • @NiklasZiermann
      @NiklasZiermann  9 місяців тому

      If you want every source to work independently, then you'll need one audio object per source

  • @Diamondyy
    @Diamondyy Рік тому +1

    Hey there! I'm running into a bit of a hiccup and I hope someone can lend a hand. I'm trying to build my React app, but I keep getting this error message:
    Module parse failed: Unexpected character '�' (1:5)
    It seems to be related to the sound file (I'm using the same WAV file). Any advice on how to resolve this? Thanks in advance! 👍

    • @NiklasZiermann
      @NiklasZiermann  Рік тому

      It's probably an issue with your bundler settings. Depending on what bundler you use you'll need to configure wav files as assets/resources. This way it will import just the path to the file instead of interpreting the file as javascript. How you do this depends on your bundler (vite, webpack, bun) but just googling ' import as static asset' should probably do the trick :)

  • @haanghuy
    @haanghuy 9 місяців тому

    Hello, can you make a video tutorial on playing audio using base64 string in react native

  • @janoscodes
    @janoscodes 2 роки тому

    Thank you so much

  • @johnathanvalorant697
    @johnathanvalorant697 Рік тому

    nice m8

  • @uiltonKeyboard
    @uiltonKeyboard 2 роки тому +1

    Hey buddy, I'm using this already in my project.
    My question here is: I have some customers that is using the app on the mobile device, so when some new message comes, I dispatch a sound,
    but when the device is locked, the sound is not emitted. Do you know any workaround about this?
    Thanks in advance.

    • @NiklasZiermann
      @NiklasZiermann  2 роки тому +1

      Unfortunately I dont think that there's a workaround for that specific issue. But you might be able to use the Notifications API as a solution :)

  • @akmalabid_fip5376
    @akmalabid_fip5376 2 роки тому

    thx so much, is there any way that the volume value can be controled with input range ?

    • @NiklasZiermann
      @NiklasZiermann  2 роки тому

      Yes there is. You can controll the volume of your Audio object using the volume atrribute (0=no sound, 1=max volume).
      So just set the range of your input to be between 0 and 1 and use a useffect to change the volume attribute whenever the input's value changes.

  • @giolosaberidze3613
    @giolosaberidze3613 Рік тому

    what if i want to play different sounds on different buttons, can u help?

    • @NiklasZiermann
      @NiklasZiermann  Рік тому

      Sure, you do the same thing as shown in the video and for every button you just use another Audio object with another source-file

    • @luv.matters
      @luv.matters Рік тому

      I'm just asking the same above lol

    • @luv.matters
      @luv.matters Рік тому

      @@NiklasZiermann rather than having multiple, would it make sense to use an object?

    • @NiklasZiermann
      @NiklasZiermann  Рік тому

      @@luv.matters Using only one audio object will most likely cause issues when multiple sounds play simultaniously. So I'd recommend using one object per sound effect.
      You can of course put all of these Audio objects into a data-structure, to make accessing them easier :)

  • @bimasenaanta
    @bimasenaanta 2 роки тому

    how to make it play automatically after load

    • @NiklasZiermann
      @NiklasZiermann  2 роки тому

      Just create the 'Audio' object and run the 'play' method inside a useEffect with an empty dependency array, like shown in the video. :)

  • @nachobalo
    @nachobalo 2 роки тому

    Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you.

  • @boyywnkobe
    @boyywnkobe Рік тому

    how to stop ?

    • @NiklasZiermann
      @NiklasZiermann  Рік тому

      The Audio Object should have a .pause() method. Try using that :)

  • @omgitskuei
    @omgitskuei Рік тому

    Your solution doesnt work!!! NextJS crashes at Build stage, returning error: Module parse failed: unexpected character ' ' with MP3 files

    • @NiklasZiermann
      @NiklasZiermann  Рік тому

      Thats because you need to tell nextjs that it should handle mp3 files as resources / assets. Right now it treats your mp3 as a JS file. Once you've done that everything should work :)

    • @pixerize-me
      @pixerize-me 11 місяців тому +1

      One way to use audio in NextJS is to put your audio file in the public folder and then do, without import, just use audio = new Audio('/assets/sounds/incoming.wav');

    • @omgitskuei
      @omgitskuei 11 місяців тому

      This worked! Can't thank you enough,@@pixerize-me !

  • @turgunov28
    @turgunov28 Рік тому

    thanks man