全部动态动态详情

添加网易云音乐播放组件不能自动播放的解决办法?

添加了网易云音乐的播放代码后,有时候不能自动播放,网易云音乐官方的引用代码如下:

<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=190 height=86 src="//music.163.com/outchain/player?type=2&id=473115525&auto=1&height=66"></iframe>

不能自动播放时控制台会提示:

Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first. https://goo.gl/xX8pDD

看看 https://goo.gl/xX8pDD ,大概意思就是说为了避免网页音乐给用户带来困恼,Chrome从Version 66后增加了控制:

Chrome浏览器的自动播放政策将于2018年4月更改。

网易云音乐是用iframe来嵌入的,看看“顶部框架可以将自动播放权限委派给其iframe,以允许自动播放声音。”这个能否解决。

官方介绍了解决方法:

<!-- Autoplay is allowed. -->
<iframe src="https://cross-origin.com/myvideo.html" allow="autoplay">

<!-- Autoplay and Fullscreen are allowed. -->
<iframe src="https://cross-origin.com/myvideo.html" allow="autoplay; fullscreen">

改一下原来的网易云音乐引用代码:

<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=190 height=86 src="//music.163.com/outchain/player?type=2&id=473115525&auto=1&height=66" allow="autoplay"></iframe>

再尝试刷新几次首页,发现可以自动播放了。(注:也并不是每次都可以,但是感觉概率比之前大了)

聊两句

说点什么,和我聊聊吧。

写下你的评论

邮箱不会被公开。标有 * 的项目为必填项。

I'M LIANG DONG

探索

梁棟Leo Liang我的名片
90 条动态2 条回应
登录后发动态

按分类浏览

按月份找回忆
邮件联系

外观

PERSONAL CARD / 個人名片

梁棟

Leo Liang

高級創新經理

創新優化中心

中國銀行(香港)有限公司

个人名片二维码扫码交换名片
liangdong.me

复制与分享

长按或选中下方内容进行复制。

搜索回忆

输入关键词,找回某个瞬间。