Muted Autoplay in Chrome still not working

前端 未结 5 669
攒了一身酷
攒了一身酷 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

    For those creating elements in JavaScript, here is the JavaScript function I'm using to configure elements to autoplay properly in Chrome:

    function configureVideoElementForAutoplay (videoElement) {
      videoElement.setAttribute('playsinline', '');
      videoElement.setAttribute('muted', '');
      videoElement.setAttribute('autoplay', '');
      videoElement.muted = true;
    }
    

    Example:

    let vid = document.createElement('video');
    configureVideoElementForAutoplay(vid);
    

    Credit to @Jonny Green for pointing out the necessity of the direct 'muted' property assignment.

提交回复
热议问题