开发者

How to Play Youtube video in webview in android?

开发者 https://www.devze.com 2023-01-31 13:37 出处:网络
I want to play a YouTube video in webview in andr开发者_高级运维oid, which should not open in a new window. It should only play in webview on android.You can try this one, it works for me.

I want to play a YouTube video in webview in andr开发者_高级运维oid, which should not open in a new window. It should only play in webview on android.


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");


Try Android Youtube Player API read more here : https://developers.google.com/youtube/android/player/

0

精彩评论

暂无评论...
验证码 换一张
取 消