Playing Sounds in Your React App | Tutorial

  Рет қаралды 25,279

Niklas Ziermann

Niklas Ziermann

Күн бұрын

Sometimes you might like your website to play music or sound effects, so let's take a look at how you might play sounds using React.
I hope this video can help you. If it does then please consider subscribing and giving me some feedback.
Have a great day!
My GitHub: GitHub.com/N-Ziermann
My Website: n-ziermann.github.io?en
Timestamps:
00:00 Starting Point
00:16 Playing Sounds onClick
01:11 Playing Sounds based on React Events (useEffect)

Пікірлер: 60
@kandekore
@kandekore Жыл бұрын
after many Stackoverflow and youtube search, this video provided a simple solution. Thank you
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome. I'm glad I could help :)
@lucasmarques2871
@lucasmarques2871 Жыл бұрын
Straight to the point, thank you very much!
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome :)
@brandonmchugh9821
@brandonmchugh9821 Жыл бұрын
Amazing. This is exactly what I was looking for. THanks!!!!!
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome :)
@mobile_genshin
@mobile_genshin 4 ай бұрын
Thank you so much for this excellent tutorial🙏 straight to the point
@NiklasZiermann
@NiklasZiermann 4 ай бұрын
You're welcome. I'm glad I could help :)
@seraphitssingh973
@seraphitssingh973 Жыл бұрын
This is what I need. Thank you.
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome :)
@sebastianlozano7707
@sebastianlozano7707 3 ай бұрын
straigth to the point! Thanks so much
@NiklasZiermann
@NiklasZiermann 3 ай бұрын
You're welcome :)
@c_zeroyt2556
@c_zeroyt2556 Жыл бұрын
Thank you , best one on youtube
@chrisgraham2123
@chrisgraham2123 Жыл бұрын
perfect man subbed, thanks a ton!
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome. I'm glad you enjoyed the video :)
@harshitsuyal8285
@harshitsuyal8285 Жыл бұрын
Thankyou so much brother it’s very helpfull
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome :)
@andrew52600
@andrew52600 5 ай бұрын
Excellent video.
@NiklasZiermann
@NiklasZiermann 5 ай бұрын
Thank you :)
@Tube-hn9rc
@Tube-hn9rc 6 ай бұрын
thank you sir that is really helpfull
@NiklasZiermann
@NiklasZiermann 6 ай бұрын
You're welcome! I'm glad I could help :)
@janoscodes
@janoscodes Жыл бұрын
Thank you so much
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome :)
@lucasmanoel208
@lucasmanoel208 7 ай бұрын
Thank you, meu chapa!
@NiklasZiermann
@NiklasZiermann 7 ай бұрын
You're welcome :)
@web.mayk3l
@web.mayk3l 2 ай бұрын
Nice video
@NiklasZiermann
@NiklasZiermann 2 ай бұрын
Thanks, I'm glad you liked it :)
@reise254
@reise254 Жыл бұрын
(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 Жыл бұрын
That's unfortunate. Sorry to hear that... But thank you for pointing out an alternative solution :)
@amanrubey
@amanrubey 5 ай бұрын
thanks!!!!! howler indeed worked, nothing else was working and I was exasperated and so depressed
@akmalabid_fip5376
@akmalabid_fip5376 Жыл бұрын
thx so much, is there any way that the volume value can be controled with input range ?
@NiklasZiermann
@NiklasZiermann Жыл бұрын
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.
@johnathanvalorant697
@johnathanvalorant697 Жыл бұрын
nice m8
@haanghuy
@haanghuy 2 ай бұрын
Hello, can you make a video tutorial on playing audio using base64 string in react native
@Diamondyy
@Diamondyy 8 ай бұрын
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 8 ай бұрын
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 :)
@uiltonKeyboard
@uiltonKeyboard Жыл бұрын
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 Жыл бұрын
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 :)
@payamrezaei-eg8dz
@payamrezaei-eg8dz 2 ай бұрын
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 2 ай бұрын
If you want every source to work independently, then you'll need one audio object per source
@luv.matters
@luv.matters 6 ай бұрын
Now how do you do it with multiple sounds like a drumkit?
@NiklasZiermann
@NiklasZiermann 6 ай бұрын
Just create one Audio object for each sound and play them accordingly :)
@giolosaberidze3613
@giolosaberidze3613 7 ай бұрын
what if i want to play different sounds on different buttons, can u help?
@NiklasZiermann
@NiklasZiermann 7 ай бұрын
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 6 ай бұрын
I'm just asking the same above lol
@luv.matters
@luv.matters 6 ай бұрын
@@NiklasZiermann rather than having multiple, would it make sense to use an object?
@NiklasZiermann
@NiklasZiermann 6 ай бұрын
@@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 Жыл бұрын
how to make it play automatically after load
@NiklasZiermann
@NiklasZiermann Жыл бұрын
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 Жыл бұрын
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.
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome :)
@boyywnkobe
@boyywnkobe Жыл бұрын
how to stop ?
@NiklasZiermann
@NiklasZiermann Жыл бұрын
The Audio Object should have a .pause() method. Try using that :)
@user-se5ts2tb7x
@user-se5ts2tb7x 4 ай бұрын
Your solution doesnt work!!! NextJS crashes at Build stage, returning error: Module parse failed: unexpected character ' ' with MP3 files
@NiklasZiermann
@NiklasZiermann 4 ай бұрын
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 3 ай бұрын
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');
@user-se5ts2tb7x
@user-se5ts2tb7x 3 ай бұрын
This worked! Can't thank you enough,@@pixerize-me !
@turgunov28
@turgunov28 Жыл бұрын
thanks man
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome :)
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 410 М.
I built a chat app in 7 minutes with React & Firebase
8:53
Fireship
Рет қаралды 1,3 МЛН
버블티로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 27 МЛН
Luck Decides My Future Again 🍀🍀🍀 #katebrush #shorts
00:19
Kate Brush
Рет қаралды 3 МЛН
Backstage 🤫 tutorial #elsarca #tiktok
00:13
Elsa Arca
Рет қаралды 45 МЛН
Using Vanilla Extract with React | Tutorial
19:56
Niklas Ziermann
Рет қаралды 4,8 М.
Why is Everyone Using Vite?
7:34
Awesome
Рет қаралды 74 М.
How to Build a Custom Audio Player in React
1:03:38
Self Teach Me
Рет қаралды 55 М.
Record and Play Audio in Expo React Native
8:31
Code Entropy
Рет қаралды 9 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 455 М.
This React UI Library is GAME CHANGER!
18:13
developedbyed
Рет қаралды 516 М.
Everything You Need to Know About React 19
21:42
CoderOne
Рет қаралды 14 М.
Learn React With This One Project
42:38
Web Dev Simplified
Рет қаралды 704 М.
버블티로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 27 МЛН