I’m loading a youtube video in a webview but the problem is that video is not playing automatically just like it does when we go to actual youtube website.In the webview video does shows up and plays but only after i push the play button which appears on the top of video.So i wanted to know if there is any way by which i can make videos play within the webview once the URL has been loaded.Following is my code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_view);
WebView wv = (WebView) findViewById(R.id.webView);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginState(PluginState.ON);
final String mimeType = "text/html";
final String encoding = "UTF-8";
String html = getHTML();
wv.setWebChromeClient(new WebChromeClient() {
});
wv.loadDataWithBaseURL("", html, mimeType, encoding, "");
}
public String getHTML() {
String html = "<iframe class=\"youtube-player\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" id=\"ytplayer\" type=\"text/html\" src=\"http://www.youtube.com/embed/"
+ "J2fB5XWj6IE"
+ "?fs=0\" frameborder=\"0\">\n"
+ "</iframe>\n";
return html;
}
Thank You!!!
add “autoplay=1” to your url