Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

how to stop audio when playing other in html

const audios_with_src = document.querySelectorAll('.audios')
const play = document.querySelectorAll('.fa-play')
const pause = document.querySelectorAll('.fa-pause-circle')
const stop = document.querySelectorAll('.fa-stop')
const main_player = document.querySelector('.main-audio')

for(let i =0; i < audios_with_src.length; i++) {
 play[i].addEventListener('click', (e) => {
    main_player.src = audios_with_src[i].src;
    main_player.play()   
    })

pause[i].addEventListener('click', () => {
    main_player.pause()
})

stop[i].addEventListener('click', () => {
    main_player.pause()
    main_player.currentTime = 0;  // there is no stop() function so had to do this
})


}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #stop #audio #playing #html
ADD COMMENT
Topic
Name
6+2 =