网站首页 > 知识剖析 正文
在切图网一个客户项目中,用到了背景音乐,采用了html5 audio标签, 并且设置了 autoplay 自动播放,在PC上正常,但是一到手机下就无法自动播放。
即便使用JS ,调用audio 对象的播放方法 play() 也不能自动播放! 这是为什么呢?
于是打破砂锅问到底的决心,做了好多种demo,例子
http://m.slicy.cn/bg-music.html
测试,苹果、安卓还是不行,最后发现真相的我,眼泪掉下来 。 原因在这:
为了防止不必要的自动播放浪费流量,手机网页访问带有audio的页面是不会自动播放的。
Safari屏蔽了autoplay,必须由用户交互事件触发,因为autoplay在移动网络环境下可能会造成用户流量费剧增
下面是引自Safari Reference
In Safari on iPhone OS (for all devices, including iPad), where theuser may be on a cellular network and be charged per data unit,
autobuffering and autoplay are disabled. No data is loaded until the
user initiates it. This means the JavaScript play() and load() methods
are also inactive until the user initiates playback, unless the play()
method is triggered by user action.
- 上一篇: Python进行AI声音克隆的端到端指南
- 下一篇: HTML DOM Video 对象
猜你喜欢
- 2025-01-08 WebRTC(一)getUserMedia 使用
- 2025-01-08 WebRTC 简述与应用
- 2025-01-08 试用MEDIASOUP:一款开源流媒体工具
- 2025-01-08 Go基于WebSocket的通讯聊天程序
- 2025-01-08 实时音视频入门学习:开源工程WebRTC的技术原理和使用浅析
- 2025-01-08 Howler.js,一款神奇的 JavaScript 开源网络音频工具库
- 2025-01-08 WebRTC → 一对一音视频实时通话
- 2025-01-08 WebRTC对等连接(一):点对点通信
- 2025-01-08 详解m3u8协议
- 2025-01-08 uni-app技术分享|uni-app转小程序_实时音视频
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)