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

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

问题描述

我正在尝试在页面的弹出窗口中自动播放 HTML5 视频(处于静音状态).加载页面时隐藏弹出窗口.当用户尝试离开页面(从顶部)时,它会显示带有自动播放和播放功能的视频弹出窗口.静音开启.然后我尝试用 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 已更新自动播放政策.参考网址

Google Chrome has updated the autoplay policies. URL for reference

根据新行为:

  1. 始终允许静音自动播放.
  2. 在以下情况下允许自动播放声音:
    • 用户与域进行了交互(点击、点击等).
    • 在桌面设备上,用户的媒体参与指数阈值已超过,表示用户之前播放过有声视频.
    • 在移动设备上,用户已将网站添加到他或她的主屏幕.

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

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