Autoplay video on mobile? Facebook Home does it. What am I missing?

后端 未结 1 1493
渐次进展
渐次进展 2021-01-17 06:58

I\'m trying to add a video to my homepage in replace of a slider.

I understand how and why mobile devices disable autoplay.

However FacebookHome and Youtub

1条回答
  •  情歌与酒
    2021-01-17 07:13

    Autoplay on most mobile platforms (Android, iOS) gets blocked to avoid poor user experiences - video should only play following a user action. You can usually work around it by triggering the play() on another event (eg the onloaded event)

    Facebook Home provides a video type extension .ogv which worked on FireFox Beta only (I tried both Google chrome And Android default browser, but it just shows the poster image)

    
    

    Demo

    Another solution is to add event listener to trigger the video to be played when the user clicks on the video element

    
    

    JS:

    var video = document.getElementById('myVideo');
    video.addEventListener('click',function(){
      video.play();
    },false);
    

    Demo Works with Firefox beta (Inside windows) But for in Android Browser it calls Video Player App to play the video

    Resources:

    • Ogg - Wikipedia
    • Android webview html5 video autoplay not working on android 4.0.3: Best answer
    • Making HTML5 Video work on Android phones

    0 讨论(0)
提交回复
热议问题