简体   繁体   中英

iOS Safari play sound without user interaction

Background:

To trigger a sound in a webpage notification under iOS safari

Fact:

I realized that safari doesn't allow sound to play without DOM interaction according to its autoplay audio policy. User has to interact with DOM after first loading of the application in someway to play sounds.

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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