Reputation: 343
I want to play a YouTube video in webview in android, which should not open in a new window. It should only play in webview on android.
Upvotes: 1
Views: 4685
Reputation: 1088
Try Android Youtube Player API read more here : https://developers.google.com/youtube/android/player/
Upvotes: 0
Reputation: 71
You can try this one, it works for me.
WebView video = (WebView) findViewById(R.id.video);
String widthAndHeight = "width='220' height='200'";
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.getSettings().setJavaScriptEnabled(true);
video.getSettings().setPluginsEnabled(true);
video.loadData(temp,"text/html", "utf-8");
Upvotes: 3