Playing Sounds in Your React App | Tutorial

  Рет қаралды 28,427

Niklas Ziermann

Niklas Ziermann

Күн бұрын

Пікірлер: 62
@kandekore
@kandekore 2 жыл бұрын
after many Stackoverflow and youtube search, this video provided a simple solution. Thank you
@NiklasZiermann
@NiklasZiermann 2 жыл бұрын
You're welcome. I'm glad I could help :)
@linak1909
@linak1909 7 ай бұрын
Thank you so much for this excellent tutorial🙏 straight to the point
@NiklasZiermann
@NiklasZiermann 7 ай бұрын
You're welcome. I'm glad I could help :)
@brandonmchugh9821
@brandonmchugh9821 Жыл бұрын
Amazing. This is exactly what I was looking for. THanks!!!!!
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome :)
@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 9 ай бұрын
thanks!!!!! howler indeed worked, nothing else was working and I was exasperated and so depressed
@sebastianlozano7707
@sebastianlozano7707 7 ай бұрын
straigth to the point! Thanks so much
@NiklasZiermann
@NiklasZiermann 7 ай бұрын
You're welcome :)
@Diamondyy
@Diamondyy 11 ай бұрын
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 11 ай бұрын
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 :)
@c_zeroyt2556
@c_zeroyt2556 Жыл бұрын
Thank you , best one on youtube
@maxs_hidden
@maxs_hidden 2 ай бұрын
Good video. Thanks!
@harshitsuyal8285
@harshitsuyal8285 Жыл бұрын
Thankyou so much brother it’s very helpfull
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome :)
@web.mayk3l
@web.mayk3l 6 ай бұрын
Nice video
@NiklasZiermann
@NiklasZiermann 6 ай бұрын
Thanks, I'm glad you liked it :)
@andrew52600
@andrew52600 8 ай бұрын
Excellent video.
@NiklasZiermann
@NiklasZiermann 8 ай бұрын
Thank you :)
@Tube-hn9rc
@Tube-hn9rc 9 ай бұрын
thank you sir that is really helpfull
@NiklasZiermann
@NiklasZiermann 9 ай бұрын
You're welcome! I'm glad I could help :)
@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.
@omgitskuei
@omgitskuei 7 ай бұрын
Your solution doesnt work!!! NextJS crashes at Build stage, returning error: Module parse failed: unexpected character ' ' with MP3 files
@NiklasZiermann
@NiklasZiermann 7 ай бұрын
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 6 ай бұрын
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 6 ай бұрын
This worked! Can't thank you enough,@@pixerize-me !
@giolosaberidze3613
@giolosaberidze3613 10 ай бұрын
what if i want to play different sounds on different buttons, can u help?
@NiklasZiermann
@NiklasZiermann 10 ай бұрын
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 9 ай бұрын
I'm just asking the same above lol
@luv.matters
@luv.matters 9 ай бұрын
@@NiklasZiermann rather than having multiple, would it make sense to use an object?
@NiklasZiermann
@NiklasZiermann 9 ай бұрын
@@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 :)
@janoscodes
@janoscodes Жыл бұрын
Thank you so much
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome :)
@johnathanvalorant697
@johnathanvalorant697 Жыл бұрын
nice m8
@boyywnkobe
@boyywnkobe Жыл бұрын
how to stop ?
@NiklasZiermann
@NiklasZiermann Жыл бұрын
The Audio Object should have a .pause() method. Try using that :)
@turgunov28
@turgunov28 Жыл бұрын
thanks man
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome :)
@lucasmarques2871
@lucasmarques2871 Жыл бұрын
Straight to the point, thank you very much!
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome :)
@haanghuy
@haanghuy 5 ай бұрын
Hello, can you make a video tutorial on playing audio using base64 string in react native
@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 5 ай бұрын
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 5 ай бұрын
If you want every source to work independently, then you'll need one audio object per source
@luv.matters
@luv.matters 9 ай бұрын
Now how do you do it with multiple sounds like a drumkit?
@NiklasZiermann
@NiklasZiermann 9 ай бұрын
Just create one Audio object for each sound and play them accordingly :)
@seraphitssingh973
@seraphitssingh973 Жыл бұрын
This is what I need. Thank you.
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome :)
@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 :)
@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. :)
@chrisgraham2123
@chrisgraham2123 Жыл бұрын
perfect man subbed, thanks a ton!
@NiklasZiermann
@NiklasZiermann Жыл бұрын
You're welcome. I'm glad you enjoyed the video :)
@lucasmanoel208
@lucasmanoel208 10 ай бұрын
Thank you, meu chapa!
@NiklasZiermann
@NiklasZiermann 10 ай бұрын
You're welcome :)
Modern Data Fetching in React (Complete Guide)
16:41
Cosden Solutions
Рет қаралды 48 М.
10 React Antipatterns to Avoid - Code This, Not That!
8:55
Fireship
Рет қаралды 748 М.
Incredible: Teacher builds airplane to teach kids behavior! #shorts
00:32
Fabiosa Stories
Рет қаралды 10 МЛН
Самое неинтересное видео
00:32
Miracle
Рет қаралды 2,9 МЛН
ПРИКОЛЫ НАД БРАТОМ #shorts
00:23
Паша Осадчий
Рет қаралды 6 МЛН
I built a chat app in 7 minutes with React & Firebase
8:53
Fireship
Рет қаралды 1,4 МЛН
Why use Type and not Interface in TypeScript
14:12
ByteGrad
Рет қаралды 207 М.
Every React 19 Feature Explained in 8 Minutes
7:35
Code Bootcamp
Рет қаралды 128 М.
All useEffect Mistakes Every Junior React Developer Makes
22:23
Optimizing Rendering Performance in React
7:50
Software Developer Diaries
Рет қаралды 76 М.
State Managers Are Making Your Code Worse In React
13:33
Web Dev Simplified
Рет қаралды 186 М.
The Most Important Design Pattern in React
35:04
Cosden Solutions
Рет қаралды 53 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 478 М.