Automatic playback of background music (compatible with iOS and Android)

Source: Internet
Author: User

iOS to save user traffic, preload and autopaly tags for audio and video tags are automatically blocked,

This is done unless the user clicks the interaction manually.

But for the background music, it must be loaded when the time to execute, how to do, directly call JS from the dynamic trigger.

<audio id= "Bgaudio" src= "./media/bg-music.mp3" loop= "loop" ></audio><script type= "Text/javascript" >document.getelementbyid (' Bgaudio '). Play ();</script>

No doubt, just a few lines of code, compatible with iOS and Android

Of course there are special iOS settings are not compatible, we can use the following way, but note only in the browser open

<audio preload= "preload" Controls id= "Car_audio" src= "./media/bg-music.mp3" loop></audio><script> SetTimeout (function () {     $ (window). scrolltop (1);},0);  document.getElementById (' Car_audio '). Play ();  Document.addeventlistener ("Weixinjsbridgeready", function () {Weixinjsbridge.invoke (' Getnetworktype ', {}, function ( e) {            document.getElementById (' Car_audio '). Play ();});  }, False);</script>


Automatic playback of background music (compatible with iOS and Android)

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.