How to autoplay HTML5 mp4 video on Android?

后端 未结 15 1071
一向
一向 2020-11-27 05:53

I had developed a mobile page by asp.net to play mp4 video.

I know iOS had disabled the autoplay function to minimize user bandwidth, so how can i autoplay HTML5 mp

15条回答
  •  醉酒成梦
    2020-11-27 06:14

    I used the following code:

    // get the video
    var video = document.querySelector('video');
    // use the whole window and a *named function*
    window.addEventListener('touchstart', function videoStart() {
      video.play();
      console.log('first touch');
      // remove from the window and call the function we are removing
      this.removeEventListener('touchstart', videoStart);
    });
    

    There doesn't seem to be a way to auto-start anymore.

    This makes it so that the first time they touch the screen the video will play. It will also remove itself on first run so that you can avoid multiple listeners adding up.

提交回复
热议问题