Display youtube videos as embed in android
Can any one please help开发者_如何学Python me to embed a YouTube video in the android WebView?
I've tried as follows but nothing is dispayed.
browser = (WebView)findViewById(R.id.webshow);
String html_head = "<html><body>";
String load =html_head+" <iframe class=\"youtube-player\" type=\"text/html\" " +
"width=\"640\" height=\"385\" src=\"http://www.youtube.com/embed/bIPcobKMB94\" frameborder=\"0\"></body></html>";
browser.loadData(load, "text/html", "UTF-8");
Try doing this
mWebView.getSettings().setPluginState(PluginState.ON);
mWebView.getSettings().setJavaScriptEnabled(true);
This worked for me so you can try as well
video = (WebView) v.findViewById(R.id.videoview);
String widthAndHeight = "width='300' height='305'";
String videoURL = "http://www.youtube.com/v/DZi6DEJsOJ0?fs=1&hl=nl_NL";
String temp = "<object "+widthAndHeight+">" +
"<param name='allowFullScreen' value='false'>" +
"</param><param name='allowscriptaccess' value='always'>" +
"</param><embed src='"+ videoURL +"'" +
" type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true'" + widthAndHeight +
"></embed></object>";
video.setHorizontalScrollBarEnabled(false);
video.setVerticalScrollBarEnabled(false);
video.getSettings().setJavaScriptEnabled(true);
video.getSettings().setPluginsEnabled(true);
video.loadData(temp,"text/html", "utf-8");
精彩评论