1

I've seen posts complaining that you cannot autoplay a video on mobile device.

But, this CAN be done. I've visited youtube website on android and iOS and video does indeed start to play without any user interaction. How can I mimic this behaviour?

EDIT: if you visit direct link, it does not work. If you first visit youtube.com and than click on some video, it works. No idea why.

sanjihan
  • 5,592
  • 11
  • 54
  • 119
  • https://webkit.org/blog/6784/new-video-policies-for-ios/ and https://developers.google.com/web/updates/2016/07/autoplay from https://stackoverflow.com/questions/20499341/html5-video-autoplay-on-mobile-browser – Michael Coker Jun 30 '17 at 17:26
  • Just don't do it! I sure don't want auto videos eating through my precious data allowances! – Ian Jun 30 '17 at 18:21
  • I understand your concerns. Mute gifs are 5x as big as mp4 video, yet nobody gives a damn. – sanjihan Jun 30 '17 at 18:26

2 Answers2

0
    <video id="mobilevideo" name="Mobile video" onLoad="play()" onClick="play()" preload="auto" autoplay preload muted playsinline webkit-playsinline>
            <source src="file.webm" type="video/webm">
            <source src="file.ogg" type="video/ogg">
            <source src="file.mp4" type="video/mp4">
            Your browser does not support this file type.
</video>

<!--Javascript autoplay video -->
<script>
    document.getElementById('mobilevideo').play();
</script>
-2

You can use autoplay in video tag. like this:

<video width="320" height="240" controls autoplay>

For more information, you can learn from here: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_video_autoplay

For mobile, you should not do auto play because it will cost user's bandwidth(money). See this post for more detail: Can you autoplay HTML5 videos on the iPad?

Jack Luo
  • 333
  • 3
  • 5
  • 3
    for mobile, you should not do auto play because it will cost user's bandwidth(money). See this post for more detail: https://stackoverflow.com/questions/12496144/can-you-autoplay-html5-videos-on-the-ipad – Jack Luo Jun 30 '17 at 17:32
  • @JackLuo, very correctly and well said, you should post this in your answer with a update. – divy3993 Jun 30 '17 at 17:58