Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
I want to call a function when my playing sound is finished in HTML and JAVASCRIPT

I want to play a sound by click the play button - it changed to a pause button and when I click the pause button it paused the sound and changed to play button, button when the sound finishes, I want to change it from the Pause button to the Play Button to play Again. Here is the Code: CSS:

.play-button {
    display: none
}

.play-button.show {
    display: block;
}
.pause-button {
    display: none;
}

.pause-button.show {
    display: block
}

for HTML:

<audio id="audio" src="name.mp3">
    Your browser does not support the audio element.
</audio>
<button class="play-button show" id="play-button" onclick="PlayButtonHide()">Play</button>
<button class="pause-button" id="pause-button" onclick="PauseButtonShow()">Pause</button>

for JavaScript:

var play-button = document.getElementById('play-button')
var pause-button = document.getElementById('pause-button')
var audio = document.getElementById("audio");
var duration = document.getElementById("myAudio").duration;
function PlayButtonHide() {
    pause-button.classList.add('show')
    pause-button.setAttribute('onclick', 'PlayButtonShow()');
    play-button.classList.remove('show')
    audio.play()
}
function PlayButtonShow() {
    play.classList.add('show')
    pause.classList.remove('show')
    x.pause()
    play.setAttribute('onclick', 'PlayButtonHide()');
}
function PauseButtonShow() {
    pause-button.classList.add('show')
    pause-button.setAttribute('onclick', 'PauseButtonHide()');
    play-button.classList.remove('show')
}
function PauseButtonHide() {
    pause-button.classList.remove('show')
    pause-button.setAttribute('onclick', 'PauseButtonShow()');
    play-button.classList.add('show')
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In the HTML Code audio Tag, Add this attribute with its value:

<audio id="audio" src="name.mp3" onended="PlayButtonShow()">
    Your browser does not support the audio element.
</audio>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!