HTML5 audio labels can no longer be played automatically on a mobile device

Source: Internet
Author: User

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);

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.