While still not perfect, this worked for me:
var audio_file = new Audio('whatever.mp3')
audio_file.addEventListener('timeupdate', function(){
var buffer = .44
if(this.currentTime > this.duration - buffer){
this.currentTime = 0
this.play()
}
});
Experiment with the size of the buffer to find what works best for you
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…