I created a function that starts an audio notification when the page footer is opened. Works perfectly in desktop versions but does not work in mobile versions. Do you have any advice on how to solve? Thanks.
/**
* Play Notification Sound
*/
function custom_um_notification_feed_sound() {
$myAudioFile = "<audio src='https://www.example.com/fischio.mp3' autoplay></audio>";
echo $myAudioFile;
}
add_action( 'wp_footer', 'custom_um_notification_feed_sound', 9999 );
/*
Don't worry this is feature on mobile phones, to save visitors from annoying videos on autoplay ;) you can do workaround, add some JS script to pay thatsound when footer DIV is touched. https://developers.google.com/web/updates/2016/07/autoplay
Add id to audio <audio id="footerAudio" src='https://www.example.com/fischio.mp3' autoplay></audio>
And some jQuery to footer or to one of loaded js files
jQuery('.footer').on({ 'touchstart' : function(){jQuery("#footerAudio")[0].play();} });
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.