html - disable audio from keeping playing after lock screen or press home button in safari -


i'm working on project , in case need play audio using tag in web. found out audio won't stop after lock screen or press home button. keeps playing. there way disable that? btw tried simplest way audio won't stop. here's code:

<html>     <body>         <audio src="./movies/1.mp3" controls="controls">             browser not support audio element.         </audio>     </body> </html> 

maybe. can listen event hitting home button or lock screen , pause()? don't know if possible.

make use of loop, check if user on webpage. store time.

here code jquery:

var lastseen var loop = function (){     lastseen = date.now()     settimeout(loop, 50) } loop() var media = $('audio, video') media.each(function () {   this.addeventlistener('timeupdate', function () {     if(date.now() - lastseen > 100) {       this.pause()     }   }, false) }) 

source: stop html5 audio looping when ios safari closed


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -