How to implement the HTML5 page audio video automatically plays under WeChat and APP

This article shared everyone about how to implement the HTML5 page audio video to automatically play under WeChat and App. Xiaobian feels quite practical, so share it with you to do a reference. Let’s take a look at Xiaobian.

Most of the H5 pages are realized to play background music, play video features. How do you realize automatic play?

Pure H5 page does not implement automatic playback, the mobile browser is disabled by VIDEO and AUDIO’s AutoPlay feature and many mobile browsers do not support the first JS call play method for playback ( Only when the user is handed over, then pause, then use the code to make Play).

This is mainly to prevent unnecessary automatic playback waste traffic.

The following code is the automatic playback of the user’s first touch, and the automatic playback of the WeChat app

function autoplaymusic () {/ * automatically play music effect, solve browser or APP Autoplay * / function musicInBrowserHandler () {musicPlay (true); document.body.removeEventListener ( ‘touchstart’, musicInBrowserHandler);} document.body.addEventListener ( ‘touchstart’, musicInBrowserHandler); / * Auto play Musical effect, solve WeChat automatic playback problem * / function musicinweixinhandler () {musicplay (true); document.addeventlistener (“weixinjsBridgeReady “, function () {musicPlay (true);}, false); document.removeEventListener ( ‘DOMContentLoaded’, musicInWeixinHandler);} document.addEventListener ( ‘DOMContentLoaded’, musicInWeixinHandler);} function musicPlay (isPlay) {var media = Document.getElementByid (‘mymusic’); if (isplay && media.paused) { ();} if (! isplay&&! media.paused) {media.pause ();}}

Thank you for reading! About how to implement HTML5 page audio video to share it here, I hope that the above can help everyone, let everyone learn more knowledge. If the article is good, you can share it out to let more people see it!
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment