简体   繁体   English

无法检测和畅通无阻的自动播放

[英]Undetectable and Unblocked auto-play

Auto play getting muted in both firefox and chrome. firefox 和 chrome 中的自动播放静音。 How can we code, so it won't get blocked by browsers.我们如何编码,这样它就不会被浏览器阻止。

My Code:我的代码:

  <audio id="audio1" src="https://notificationsounds.com/storage/sounds/file-sounds-1217-relax.mp3" autoplay="">
  <script>
     a = document.getElementById('audio1');
     
     a.onended = function(){setTimeout("a.play()", 1000)}
  </script>

This is a browser feature and it is enforced by a policy.这是一项浏览器功能,由策略强制执行。 Your page must have some continuous activity in order to do so.您的页面必须有一些持续的活动才能这样做。

As suggested by the comments, you can indeed wait for onClick events in order to trigger your playback.正如评论所建议的,您确实可以等待onClick事件来触发您的播放。

Technically speaking, the referenced document says that for a developer standpoint of view you can alter them to perform specific tests:从技术上讲,参考文档说,从开发人员的角度来看,您可以更改它们以执行特定测试:

You can disable the autoplay policy entirely by using a command line flag: chrome.exe --autoplay-policy=no-user-gesture-required.您可以使用命令行标志完全禁用自动播放策略:chrome.exe --autoplay-policy=no-user-gesture-required。 This allows you to test your website as if user were strongly engaged with your site and playback autoplay would be always allowed.这使您可以测试您的网站,就好像用户与您的网站密切互动一样,并且始终允许播放自动播放。

You can also decide to make sure autoplay is never allowed by disabling MEI and whether sites with the highest overall MEI get autoplay by default for new users.您还可以决定通过禁用 MEI 来确保永远不允许自动播放,以及是否默认为新用户自动播放具有最高总体 MEI 的站点。 Do this with flags: chrome.exe --disable-features=PreloadMediaEngagementData, MediaEngagementBypassAutoplayPolicies.使用标志执行此操作:chrome.exe --disable-features=PreloadMediaEngagementData、MediaEngagementBypassAutoplayPolicies。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM