Chrome video autoplay

前端 未结 6 1655
鱼传尺愫
鱼传尺愫 2021-01-19 23:06

Following Chrome & Firefox\'s recent update autoplay videos are no longer supported - I\'ve tried to add some code to play this on startup but it doesn\'t seem to work?<

6条回答
  •  孤城傲影
    2021-01-19 23:37

    I have two solutions that don't need any attributes or iframe and it can autoplay audio / video with sound also, please follow me:

    1. WebRTC Solution:

    navigator.mediaDevices.getUserMedia({ audio: true }).then(function (stream) {
        vid.play(); // play your media here then stop the stream when done below...
        stream.getTracks().forEach(function (track) { track.stop(); });
    });
    

    It will ask users for their Microphone permission and they have to click Allow once then you are permitted to play anything with / without sound. It works because as long as you are capturing anything then you are allowed to play everything. Source: autoplay-restrictions-and-webrtc

    2. Manual Solution: If for some reason users don't want to give their microphone permission then only you can do to convince them the fact that you only need this permission for playing media automatically for them, it has nothing to do with their microphone because you are stopping it as soon as the media starts playing. Otherwise, instruct them to Allow Sound permission from your site settings, that will also grant access to play media with or without sound permanently.

    After two days of continuous searching and before giving up the hope to autoplay audio/video with/without sound I have come up with these two solution that simply works without any user gestures. I hope it'll solve any autoplay related issues happening after the new strict policy deployed by google. Read more: autoplay-policy-changes

提交回复
热议问题