For more information about the automatic playback of H5 page audio and video on WeChat and apps, h5app

Source: Internet
Author: User

For information about automatic playback of H5 page audio and video under and app, h5app

Automatic playback of audio and video on H5 pages

Currently, most H5 pages support playing background music and videos. How can we achieve automatic playback?

The pure H5 page cannot be automatically played on the mobile phone. Most mobile browsers disable the autoplay function of video and audio.
In addition, many mobile browsers do not support the first JavaScript call of the play method for playback (only when you manually click the play and pause it, and then use the code for play ).
This is mainly used to prevent unnecessary automatic playback from wasting traffic.

The following code is used to enable playback after the first touch and automatic playback under the app.

1 function autoPlayMusic (){
2/* automatically play the music effect to solve the problem of automatic playback by the browser or APP */3 function musicInBrowserHandler () {4 musicPlay (true); 5 document. body. removeEventListener ('touchstart', musicInBrowserHandler); 6} 7 document. body. addEventListener ('touchstart', musicInBrowserHandler); 8/* automatically play the music, solving the problem of automatic playback */9 function musicInWeixinHandler () {10 musicPlay (true); 11 document. addEventListener ("WeixinJSBridgeReady", function () {12 musicPlay (true ); 13}, false); 14 document. removeEventListener ('domainloaded', musicInWeixinHandler); 15} 16 document. addEventListener ('domainloaded', musicInWeixinHandler); 17} 18 function musicPlay (isPlay) {19 var media = document. getElementById ('mymusic'); 20 if (isPlay & media. paused) {21 media. play (); 22} 23 if (! IsPlay &&! Media. paused) {24 media. pause (); 25} 26}

 

The above is for reference only. Hope the experts can help you revise a better and more comprehensive approach.

Prepared by: Night 10:25:54

 

 

 

 

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.