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
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)
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!
@@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 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?
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
👍 for the video. I wish you named the variable, "play" differently so it doesn't confuse beginners with the method, "play" within the function.
Noted.
thank you! i needed an option to include a pronunciation of my name in a portfolio and this is a life saver!
Glad to hear that
Thank You so much Man! I looked for this everywhere and at last it was your video which finally Helped me. Really Thank You!
Glad I could help! Thanks for watching Ayush
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!!!!🥰
Thanks for watching. Enjoy playing audio files
Straight to the point, thanks!
Thanks for watching
Thank you for the knowledge shared.
Glad it was helpful! Thanks
Thanks! Exactly what I was looking for to upgrade my website!
Glad I could help!
Thank you! Kind and generous, helped me a lot!
You're welcome! I'm glad I could help.
Great video, liked and subscribed
Big thanks
thank you i needed this, also this was clear fast and very easy to understand
Glad it helped! I hope you like and subscribe
thanks man keep it up
شكرا اخى لقد استمتعت بمشاهدة فيديوهاتك
I am happy انا سعيد
thank you شكرا
Nice
You're the best! Thank you so much!
Glad it helped! Enjoy coding
I love it man, thanks!
Glad to hear it! Thank you for watching. I hope you like and subscribe
underrated
Thanks for watching
Thanks for best teach
Most welcome
nice tq
Thanks for watching
absolute legend!!!! Thanks :D
Glad it helped!
Thank you for the video, you helped me very much.
Glad it helped. Thanks for watching
thanks for the video. imo u should have mentioned that you were using constrcutor while explaining
You are right. I used the constructor implicitly
This is good but how do I make it stop the sound?
This video might help.
How to play and pause an audio file with JavaScript
th-cam.com/video/6q4D1O_pEdg/w-d-xo.html
@@TheWheelchairGuy thanks
very cool, thanks! :D
Thanks for watching. Please like and subscribe. The road to 20k
How do I make an image play an audio when I click it? (pls i need help)
You can basically add onclick=“functionName()” attribute to the image for example
How we do the same if audio is not in the same folder
thank you, that was very helpful for me
Glad to hear that!
Thank you!
You're welcome!
Hello, is it possible to add autoplay with audio in Safari?
Autoplay has been disabled on Chrome and Safari for personal security reasons.
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
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();
}
Thanks bro
You’re very welcome bro
Thanx
Welcome ✌️
Hi there. If I would like the audio to simply play on click/tap how do I replace the button line of code?
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
@@TheWheelchairGuy Thank you for taking the time to respond! Tis much appreciated
thank you my dude
Happy to help
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)
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!
Gracias. Me salvaste
De nada
Can you use the onclick=“ “?
Yes you can
THANKYOU
You’reWelcome
Can you pause that
Yes, you can.
Here is the code, but remember that autuplay is blocked on many browsers
Pause
const audio = document.getElementById('myAudio');
const button = document.getElementById('toggleButton');
let isPlaying = true;
button.addEventListener('click', () => {
if (isPlaying) {
audio.pause(); // Pause the audio
button.textContent = 'Play'; // Change button text
} else {
audio.play(); // Play the audio
button.textContent = 'Pause'; // Change button text
}
isPlaying = !isPlaying; // Toggle the state
});
Tq u
thanks!
You bet!
this code not working in iphone browser
Could you please tell me what iPhone are you using?
thanks
You are welcome
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....
This works on computer, but on your mobile, the browser that you run code with might not support JavaScript Audio
@@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.
@@martapfahl940 you can use setInterval to start the function when the timer is done.
@@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?
@@martapfahl940 You can say for instance, whenever variable count down becomes zero, trigger the sound function
too confusing i only know html and css and want the text i click to play some audio
Sorry for confusion
how if want auto play?
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
doesnt work, i tried with image link and mormal image
Make sure you attach the function to an element. For instance, onclick="function()"
The audio isn’t playing
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
I cant get it to work and it's driving me mad
You can get the code here. github.com/pescad085/javaScriptAudio/blob/main/Sound.html
How to play 4 audio files?
I should make a tutorial about that
works in computer; works not in mobile.
It depends on browsers. Some browsers don’t support JavaScript and autoplay
Please don't write script code into an html file...
It is optional to write the script in the HTML file or not
🦨 🐰🐇 🕊
I don’t know what that means