Solution 1 :

I think you might need to add the controls attribute to your <audio> tag. That way you don’t need the extra button(s).

It would look like this:

<div class="buttons">
    <audio id="myaudio" controls>
        <source src="media/tasmanian-devil-daniel_simon.mp3" preload="auto">
    </audio>
</div>

Solution 2 :

Method 1 – with default control
Answer by Niels Bosman

Method 2 – with custom button

-- JS  
const myaudioInput = document.querySelector('#myaudio');

function playAudio() {
 myaudioInput.play();
}

-- HTML  
<i class="fa fa-play" onclick="playAudio()"></i>

to pause

myaudioInput.pause();

to restart

myaudioInput.pause();
myaudioInput.currentTime = 0;
myaudioInput.play();

Problem :

I am struggling to make the play icon active and play a sound. Can anyone help me?

Here is my HTML:

<div class="buttons">
    <a id="play" href="#" class="btn">
        <audio id="myaudio">
            <source src="media/tasmanian-devil-daniel_simon.mp3" preload="auto"  > 
        </audio>
        <br>
        <i class="fas fa-play"></i>
    </a>
</div>

Comments

Comment posted by Bilyana Karamfilova

I need some javascript help. 🙂

Comment posted by ROOT

its probably the URL for the audio is not right can you check the network tab in your dev tool?

Comment posted by Rob

I don’t see any javascript you have used.

Comment posted by fontawesome.com/icons/play?style=solid

Hey, yes, but i just want to have a tine play icon –

By