How to add second button playing audio on click in Webflow (With some Javascript)

How to add second button playing audio on click in Webflow (With some Javascript)

**Not work second button
6-9-2021 11-05-45 AM


source : https://www.youtube.com/watch?v=b3cYio8LkrA

Hello, can you please provide your website so I can help out

Thanks

Hi, PixZen
Thankyou

https://testaudio1.webflow.io/

<audio id="audio" src="a1.mp3?1=1"></audio>
<script>
const audioElement = document.getElementById('audio');
const playSun = document.querySelector('.play-sun');
playSun.addEventListener('click', function() {
	audioElement.play();
});
</script>

Hello FMD,

I tried all sorts of ways to play this, I guess audio tags only work when they’re referencing local audio files , not online through a link.

image

I’d suggest downloading the audio file and referencing it in the src

Hi @PixZen @FMD_Dev_Team is this something like what you are looking for?

1 Like

This is so cool. For me, this does provide some inspiration in the direction I need to go for my project. Your awesome!

Hey @redagent glad it helped, we adapted this a lot further for the client as the initial code wasn’t playing from the begining when restarted. Happy to jump on a call if you hit any blockers or need some advice.

1 Like

Certainly, I’ll keep you in mind.