简体   繁体   English

iOS Safari 在没有用户交互的情况下播放声音

[英]iOS Safari play sound without user interaction

Background:背景:

To trigger a sound in a webpage notification under iOS safari iOS safari 下网页通知触发声音

Fact:事实:

I realized that safari doesn't allow sound to play without DOM interaction according to its autoplay audio policy.我意识到 safari 根据其自动播放音频策略不允许在没有 DOM 交互的情况下播放声音。 User has to interact with DOM after first loading of the application in someway to play sounds.在首次加载应用程序后,用户必须以某种方式与 DOM 交互才能播放声音。

setInterval(function(){
       if(condition)
       sound.play();
    }.bind(this), 1000);

Works:作品:

Plan B would be the iOS safari push notification but currently it is not released until 2023 later.计划 B 将是 iOS safari 推送通知,但目前它要到 2023 年以后才会发布。

I would like to seek for your advice the solution or alternative to implement a sound trigger webpage under a scheduled interval in webpage.我想征求您的意见,以在网页的预定间隔内实施声音触发网页的解决方案或替代方案。

Thanks.谢谢。

You can play any sound after the first DOM interaction.您可以在第一次 DOM 交互后播放任何声音。 So for example, make the user click a button, like the login button, and play one (silent) sound.因此,例如,让用户点击一个按钮,比如登录按钮,然后播放一个(静音)声音。 After that, you are free to make sounds on interval.之后,您可以自由地按间隔发出声音。

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

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