静音自动播放视频显示错误:播放()失败,因为用户未首先与文档交互。 [英] Muted Autoplay video shows error: play() failed because the user didn't interact with the document first.

查看:379
本文介绍了静音自动播放视频显示错误:播放()失败,因为用户未首先与文档交互。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在页面的弹出窗口中制作HTML5视频自动播放(处于静音状态)。加载页面时隐藏弹出窗口。当用户试图离开页面(从顶部)时,它会显示带有AutoPlay&的视频弹出窗口。静音。然后我尝试用JavaScript播放视频,但它出现了这个错误: play()失败,因为用户没有先与文档交互。

I am trying to make an HTML5 video autoplay (in muted condition) in the popup in the page. The popup is hidden when page is loaded. When user tries to go out of page (from top), it shows video popup with AutoPlay & muted ON. Then I tried to play video with JavaScript but it gives this error: play() failed because the user didn't interact with the document first.

如果我在页面上的某个位置单击或者在显示视频弹出窗口之前打开了开发人员面板,它可以正常工作。我正在使用Flow Player,并且仅在Google Chrome中发布(在FF上正常工作)。

It works fine if I click somewhere on page or if developer panel is open before the video popup is displayed. I am using Flow Player, and issue only in Google Chrome (works fine on FF).

您能否就如何克服这个问题提出任何想法?

Can you please give any ideas on how to overcome this?

谢谢,J

推荐答案

谷歌浏览器已更新自动播放政策。
供参考的网址

Google Chrome has updated the autoplay policies. URL for reference

根据新行为:


  1. 始终允许静音自动播放。

  2. 如果符合以下条件,则允许声音自动播放:


    • 用户与域名进行了互动(点击,点击等)。

    • 在桌面上,用户的媒体参与度指数阈值已超过,
      表示用户之前已播放带声音的视频。

    • 在移动设备上,用户已将该网站添加到他或她的主屏幕。

  1. Muted autoplay is always allowed.
  2. Autoplay with sound is allowed if:
    • User has interacted with the domain (click, tap, etc.).
    • On desktop,the user's Media Engagement Index threshold has been crossed, meaning the user has previously play video with sound.
    • On mobile,the user has added the site to his or her home screen.

这篇关于静音自动播放视频显示错误:播放()失败,因为用户未首先与文档交互。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆