"Go" audio does not automatically play on iOS

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.