How do I detect if the HTML5 autoplay attribute is supported?

前端 未结 9 747
遇见更好的自我
遇见更好的自我 2020-12-05 05:04

How do I best detect whether a browser\'s HTML5 video element supports autoplay?

On current iOS Safari, for example, autoplay is disabled.

Update:

9条回答
  •  情歌与酒
    2020-12-05 05:22

    Maybe I respond a little bit late but I just test a solution which work fine for me :

    var loadStarted = false;
    
    video.onloadstart = function(){
        loadStarted = true;
    };
    
    function checkRunning(){
        if(!loadStarted) removeVideo();
    }
    
    setTimeout(checkRunning, 1000);
    

    The setTimeout is not very clean, but the overall solution is super simple like that !

提交回复
热议问题