Muted Autoplay in Chrome still not working

前端 未结 5 667
攒了一身酷
攒了一身酷 2020-12-16 23:39

I am having trouble getting chrome to autoplay a video. I have set the video to muted and it auto plays in both Safari and Firefox but not chrome.

                  


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-17 00:18

    Although @richard-lindner's solution didn't work for me, it put me on the right track.

    In my case, although the muted attribute was present, Chrome was ignoring it and failing silently unless it was also explicitly set in javacript e.g.

    var video = document.getElementById("myVideo");
    video.oncanplaythrough = function() {
        video.muted = true;
        video.play();
    }
    

    Interestingly, forcing the autoplay using javascript but ommitting the video.muted = true line did display the autoplay policy error in the console, suggesting Chrome is indeed ignoring the muted attribute in some cases. This to me feels like a bug with Chrome's autoplay policy.

    Note that the error occurred only when the video was not cached. If it was cached, autoplay worked as expected.

提交回复
热议问题