Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTube iframe embeds cannot autoplay on Android

I'm using a webView in my Android app to load YouTube iframe player and auto play videos. It works fine on Samsung Galaxy S2 & S3, but when runs on Samsung Galaxy S4, it always results in gray screen when trying to auto play.

On Galaxy S4, it works fine without autoplay, needs user action(click) to start playing (Nothing happened if adding "autoplay:1" in playerVars).

I tried to call player.playVideo() in onPlayerReady(), it resulted in this gray screen:

enter image description here

The LogCat also shows a weird error message:

E/IMGSRV(17004): :0: GetPTLAFormat: Invalid format

when failed to autoplay. I don't know what this message is about; I've googled it and found nothing.

Here's the Android code of WebView:

WebView wv = (WebView) findViewById(R.id.webview);
WebSettings websettings = wv.getSettings();
websettings.setJavaScriptEnabled(true);
websettings.setDomStorageEnabled(true);
websettings.setDatabaseEnabled(true);
wv.loadUrl(strUrl);
wv.setWebViewClient(new WebViewClient());
wv.setWebChromeClient(new WebChromeClient());
wv.setPadding(0, 0, 0, 0);
wv.getSettings().setLoadWithOverviewMode(true);
wv.getSettings().setUseWideViewPort(true);
wv.setVerticalScrollBarEnabled(false);
wv.setHorizontalScrollBarEnabled(false);

Is this a known issue or if there's any solution to autoplay the video? Thanks!

like image 876
iForests Avatar asked May 07 '13 10:05

iForests


People also ask

How do I Autoplay an embedded YouTube video on mobile?

To make an embedded video autoplay, add "&autoplay=1" to the video's embed code right after the video ID (the series of letters that follows "embed/").

How do I Autoplay YouTube videos on Android?

Autoplay on the YouTube app on your TVGo to Settings . Scroll to Autoplay. Select the options to turn Autoplay On or Off.

Why is autoplay not working on YouTube app?

AutoPlay may not work on YouTube due to corrupt cache/data of the browser or corrupt installation of the YouTube mobile application. Moreover, an outdated browser or misconfiguration of your browser like DRM settings, etc. may also cause the error under discussion.

How do I enable autoplay in iframe?

Allowing iframes to autoplay video content You should also note the need to use the allowfullscreen attribute in complement to the allow attribute in order to support browsers that do not support allow attribute. If you are using amp-iframe and autoplay you need to add allow="autoplay" to your amp-iframe element.


2 Answers

I think disabling autoplay is becoming a "standard".

  • In iOS Safari, autoplay in HTML5 tags is disabled. (http://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW4)

  • In Chrome, autoplay is also disabled. (https://code.google.com/p/chromium/issues/detail?id=159336)

  • I believe the same happens with the recent versions of the default Android Web Browser.

By the way, you could try this

EDIT:

As the link is dead, I found it in https://lumi.do/p/04x626i1ngvht/how-to-autoplay-html5-video-on-android:

How to "autoplay" HTML5 video on Android
Written by Mathias Desloges in Labs on 19/05/11

Have you ever try to play with the new HTML5 video tag on an Android device?
We have and here is an stange issue which we faced.
Let's set up the context, we want our video starts playing just after the page load complete.
According to the HTML5 specification, we should use the "autoplay" attribute, but it has no effect in Android. So we tried with a little script tha call the play function after the page has loaded:

function callback () { document.querySelector('video').play(); } 
window.addEventListener("load", callback, false);

This reproduces well the behavior of the "autoplay" attribute on a classic desktop browser, but on an Android browser it fails.
we tried to attach the previously defined "callback()" function to a click event on a arbitrary node, and the video starts playing well "on click" (normal behavior). And while continue working on the page html code, we found the solution!

Don't ask me why, but after adding the "poster" attribute it works!

like image 100
Alejandro Colorado Avatar answered Sep 28 '22 10:09

Alejandro Colorado


I believe this is a symptom of the OS manufacturers becoming more restrictive in not letting videos autoplay due to bandwidth concerns. This has been an issue on iOS for some time where any JavaScript call to play() will fail unless the user has performed some action like a click first. That is likely what is going on in your case.

like image 25
edtheprogrammerguy Avatar answered Sep 28 '22 08:09

edtheprogrammerguy