Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to autoplay HTML5 mp4 video on Android?

Tags:

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 mp4 video on Android ?

I had already put autoplay in HTML5 code, but it doesn't work.

The following is my code:

<video autoplay controls id='video1' width='100%' poster='images/top_icon.png' webkitEnterFullscreen poster preload='true'> <source src='http://192.xxx.xxx.xx/XXXXVM01.mp4' type='video/mp4; codecs='avc1.42E01E, mp4a.40.2' > </video> 

Moreover, I had fixed the problem that user click on the image overlay can play the video. Thanks Karthi

here are the code:

<script type="text/javascript">     $(document).ready(function() {     $("#video1").bind("click", function() {     var vid = $(this).get(0);     if (vid.paused) { vid.play(); }     else { vid.pause(); }     });  });  </script> 

Thanks

Joe

like image 750
Joe Yan Avatar asked Jan 31 '12 06:01

Joe Yan


People also ask

How do you autoplay videos on Android?

Tap “Settings” to configure the in-app settings. Tap on the second option in the list, the one labelled “Autoplay”. Tap “Autoplay”, it will be the second item in the settings list. To toggle autoplay on or off, simply tap the slider so the setting is disabled or enabled as preferred.

Can you autoplay video on mobile?

Mobile device settings can block autoplay Most mobile devices, including Apple iPhones, Apple iPads and many Android and Microsoft devices do not support the video autoplay feature so your video will not play automatically if a visitor is on one of these devices.

Can I autoplay a video with sound html5?

Muted autoplay is always allowed. Autoplay with sound is allowed if: User has interacted with the domain (click, tap, etc.). On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously played video with sound.

How do I enable video autoplay in HTML?

The autoplay attribute is a boolean attribute. When present, the video will automatically start playing. Note: Chromium browsers do not allow autoplay in most cases.


2 Answers

You can add the 'muted' and 'autoplay' attributes together to enable autoplay for android devices.

e.g.

<video id="video" class="video" autoplay muted >
like image 76
AngryFridges Avatar answered Nov 05 '22 11:11

AngryFridges


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.

like image 44
james2doyle Avatar answered Nov 05 '22 12:11

james2doyle