Audio Auto Play (Autoplay) music under iOS

Source: Internet
Author: User

A few days ago did a H5 activity page, product requirements to initialize play music, because know H5 audio tag support AutoPlay didn't care. After the test on the phone, found that the phone on the open page is not automatically play, click the Play button to play, it is tangled. And then I looked online to find out that the AutoPlay attribute for audio was banned on iOS for the following reasons:

User Control of Downloads over Cellular Networks

In Safari to IOS (for all devices, including IPad), where the user is on a cellular network and is charged per data un It, preload and AutoPlay are disabled. No data is loaded until the user initiates it. This means the JavaScript play () and load () methods is also inactive until the user initiates playback, unless the play () or load () method is a triggered by user action. In other words, a user-initiated play button works, but an onload= "play ()" event does not.

This plays the movie: <input type="button" value="Play" onclick="document.myMovie.play()">This does nothing on iOS: <body onload="document.myMovie.play()">

View Safari HTML5 Audio and Video Guide in detail

Google Translate to learn: Apple for the sake of the user, the AutoPlay and JS "onload" load playback is forbidden.

The official ban, and product communication, the product issued a "friend station" page to me said is can let me refer to, indeed can, but code too much, discard it.

Or go to http://search.yahoo.com to find the answer, the IBM developer found the answer:

// run on page loadvar audio = document.getElementById(‘audio‘);jQuery.ajax({url: ‘ajax.js‘,async: false,success: function() {audio.play(); // audio will play in iOS before 4.2.1}});

See more IBM Developers

But iOS4.2.1 after the failure, and now all iOS8, really no language, but also did not find other methods, on the dead horse when live horse medical test, the result, a magical scene appeared, opened unexpectedly automatically play music, ha ha ...

It's not that it's expired, why? Oh, just opened in, I again with Safari Open will not automatically play music, fortunately, we H5 activities only open inside.

OK, but the bug is coming again, the test found a Andro in the open can not automatically play, I took to try the next, indeed, and then open the "friend station" The discovery is not automatically play, product confirmation, let reference "Friends Station" optimization, that is, touch will automatically play.

document.addEventListener(‘touchstart‘, function(){     audio.play();}, false);

This time is really good, except that the android5.x system of the mobile phone, the other can be opened automatically play.

Let's summarize:

Mobile Audio Autoplay
    1. Apple thinks it's an unfriendly act.
    2. Android ditto
    3. I'm ditto.

The domestic traffic is very expensive, ouch my money ah. Is it really good for us to get around the system limits by "speculation"?

Is this really good for the user experience?

Are we really worth it?

Audio Auto Play (Autoplay) music under iOS

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.