Do a micro-letter application, want to add a background music, using HTML5 audio tag in the Computer browser can play automatically, and on the mobile device whether the set AutoPlay properties or use JS call Play () method, can not be automatically played, what is the solution.
Cause analysis
The AutoPlay property in HTML5 is set to play automatically. If this property is set, video or audio will play automatically.
But it should be noted that some browsers, such as Safari, mask the AutoPlay attribute. Because the AutoPlay in the mobile network environment may cause the user traffic expense to increase dramatically.
IOS 3.2 can be simulated by JS analog A click event to trigger, but in the later version is no longer valid, safari completely shielded AutoPlay, unless the user click to play, there is no other way to achieve autoplay
Android machines can be automatically played, there is no way in the iOS machine, you can by the page binding Touchstart events to achieve playback.
Curve to save the nation, for example:
code is as follows |
copy code |
Create The IFRAME and set its source to the media file ' s URL and append the "iframe to the" body. var ifr=document.createelement ("iframe"); Ifr.setattribute (' src ', "Http://cms.hovertree.com/hovertreesound/hovertreesnow.mp3"); Ifr.setattribute (' width ', ' 1px '); Ifr.setattribute (' height ', ' 1px '); Ifr.setattribute (' scrolling ', ' no '); ifr.style.border= "0px"; Document.body.appendChild (IFR); |