Why won't my HTML5 audio loop?

后端 未结 2 1455
长发绾君心
长发绾君心 2020-12-10 09:43

The site is up at: http://ajf.me/stuff/eva at the time of writing. The source code is this:





        
2条回答
  •  感情败类
    2020-12-10 10:23

    Firefox has not yet implemented loop. I would check that you have the newest version of Firefox, but I believe this is still the case. You can check whether or not it is supported with:

    if (typeof new Audio().loop == 'boolean')
    

    If that evaluates to true, then loop is implemented in the browser. If false, then it is not. Add that to your javascript, put an id tag on your audio and use that if statement to check for loop.

    if !(typeof new Audio().loop == 'boolean') {
        audioToLoop = document.getElementById('audio_id_here');
        audioToLoop.addEventListener('ended', function () {
            this.currentTime = 0;
            this.play();
        }, false);
    }
    

    Then it should loop even in unsupported browsers.

提交回复
热议问题