I use android webview in my app for display video from youtube it's work well.
But i want it's auto play.
This is my activity i append "?autoplay=1" to videoUrl but nothing change it's still not auto play.
public class LandVideoAct extends Activity {
WebView mWebView;
String videoURL = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.landfull);
videoURL = "http://www.youtube.com/embed/VYIi49czywo?autoplay=1";
mWebView = (WebView) findViewById(R.id.fullwebview);
String vid = "<html><body style=\"margin: 0; padding: 0\"><iframe width=\"100%\" height=\"100%\" src=\""+videoURL+"\" type=\"text/html\" frameborder=\"0\"></iframe><body><html>";
WebChromeClient mWebChromeClient = new WebChromeClient(){
public void onProgressChanged(WebView view, int newProgress) {
}
};
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mWebView.setWebChromeClient(mWebChromeClient);
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
mWebView.loadUrl("javascript:(function() { document.getElementsByTagName('video')[0].play(); })()");
}
});
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.setInitialScale(1);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
if (Build.VERSION.SDK_INT < 17) {
Log.i("GPSNETWORK", "<17");
} else {
Log.i("GPSNETWORK", Build.VERSION.SDK_INT+">=17");
mWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);
}
mWebView.loadData(vid, "text/html", "UTF-8");
}
}
I think its not possible in webview or android browsers. To achieve auto playing, I think you need "YOUTUBE API".
Check below link :
1] There's no way method to do autoplay video on android platform?
2] Youtube Api android autostart
These above links will give you idea about auto playing as well as youtube api.
It's disabled by default based on operating system reason. Chrome disables content by default, too. You can try to code your own app or use Java, Javascript and the YouTube-API instead. Maybe webkit will let you allow to decide what to play based on your battery state in the future.
Use Desktop mode on WebView. Youtube will autoplay. Add this:
Like this:
Do like this. Hope it helps
From below link
Check out this question. There are a couple of suggestions that may work for you, however the person who asked that question didn't say if it worked for them or not.
Most of what I'm reading is saying that most mobile platforms block autoplay to avoid poor user experience.
You can try this javascript code below:
For Android 4.2.2+ try adding this in your native code:
Also check out this page. Which adds the code below to autoplay the video:
This code will do the trick, I'm using jquery, but it can be done with plain javascript.