Audio elements and video elements do not play automatically in iOS and Andriod

Source: Internet
Author: User

原因: 因为各大浏览器都为了节省流量,做出了优化,在用户没有行为动作时(交互)不予许自动播放;    /音频,写法一
<audio src= "Music/bg.mp3" AutoPlay loop controls> your browser is not yet supported Oh </audio>

        //音频,写法二
<audio controls= "Controls" >         <source src= "Music/bg.ogg" type= "Audio/ogg" ></source>        < SOURCE src= "Music/bg.mp3" type= "Audio/mpeg" ></source>        //Priority play Music Bg.ogg, not supported in play Bg.mp3</ Audio>

 //JS绑定自动播放(操作window时,播放音乐)
  function () {        music.play ();    })
 //下兼容处理
function () {        music.play ();     false);

  < Span class= "hljs-string" >  summary: 1.audio element AutoPlay properties are not available on iOS and Android, normal on PC side; 2.audio element does not set controls when the iOS and Android will occupy space, while on the PC side Chrome will not occupy any space; 3. Note that you do not miss the compatibility of processing needs to reference JS;              

Audio elements and video elements do not play automatically in iOS and Andriod

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.