1

I'm stuck in a project where I want to auto play video using html5 video. It works fine on desktop browser, but on Android 4.1 default browser it requires me to "touch" (or click) video element (or play button)to play video.

I have tried number of ways:

  • use trigger
  • manually calling play function on page load
  • using autoplay attribute

but none of above works in Android browser.

One solution which I think is to simulate click event on page load but is it programmatically possible to simulate click function?

Adinia
  • 3,722
  • 5
  • 40
  • 58
  • You cannot force mobile users to autoplay video. It's a feature of the OS. It's to do with the cost of mobile bandwidth and the OS creators doing what's the in the best interests of the user. – ahren Dec 02 '12 at 19:52
  • @ahren i know its os feature but its for my client project so i am doing it for wat it is he ask for... secondly i found that if i could simulate click on element it can appear as autoplay – user1870773 Dec 02 '12 at 19:57
  • You can't do it. Simulated clicks don't count on the video element in most mobile OS's... – ahren Dec 02 '12 at 19:59
  • @ahren anyother way to perform autoplay for video – user1870773 Dec 02 '12 at 20:02

1 Answers1

0

Referring this answer.

For Android < 4.2.2 it seems that the last DOM event you get is loadeddata. You likely won't get canplaythrough. To autoplay, you then use javascript

var myvideo = document.getElementsByTagName('video')[0]; 
myvideo.play(); 

For Android 4.2.2+ all you need in your native code is

WebView.getSettings().setMediaPlaybackRequiresUserGesture(false);
Community
  • 1
  • 1