<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <Metaname= "Viewport"content= "Width=device-width, User-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <title>Fake Auto Play HTML audio in IOS Safari the right</title></Head><Body> <AudioID= "Bgmusic"autoplay preload Loop></Audio> <Script> (function() { functionlog (info) {Console.log (info); //alert (info); } functionForcesafariplayaudio () {audioel.load ();//IOS 9 also requires additional load, otherwise direct play is not availableAudioel.play ();//IOS 7/8 only needs play } varAudioel=document.getElementById ('Bgmusic'); //can automatically play when the correct sequence of events is //Loadstart //Loadedmetadata //Loadeddata //Canplay //Play //playing // //events that are triggered when the auto play is not //iPhone5 IOS 7.0.6 loadstart //Loadeddata Canplay, loadedmetadata, iphone6s IOS 9.1 loadstartAudioel.addeventlistener ('Loadstart', function() {log ('Loadstart'); }, false); Audioel.addeventlistener ('Loadeddata', function() {log ('Loadeddata'); }, false); Audioel.addeventlistener ('Loadedmetadata', function() {log ('Loadedmetadata'); }, false); Audioel.addeventlistener ('Canplay', function() {log ('Canplay'); }, false); Audioel.addeventlistener ('Play', function() {log ('Play'); //when audio is able to play, remove the eventWindow.removeeventlistener ('Touchstart', Forcesafariplayaudio,false); }, false); Audioel.addeventlistener ('playing', function() {log ('playing'); }, false); Audioel.addeventlistener ('Pause', function() {log ('Pause'); }, false); //because IOS Safari restrictions do not allow audio AutoPlay, users must actively interact (for example, click) to play audio. //so we actively play audio with a user interaction event.Window.addeventlistener ('Touchstart', Forcesafariplayaudio,false); AUDIOEL.SRC= 'Http://www.w3school.com.cn/i/song.mp3'; })(); </Script></Body></HTML>
Look at the code, presumably because the iOS built-in system will intercept audio AutoPlay, so you need an interaction, the code's interaction is when the screen is Touchstart and then starts to load the music and then play. Transfer required
"Go" audio does not automatically play on iOS